first working example from Boriel’s ZXBasic Compiler, finally

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
nitrofurano
Posts: 24
Joined: Fri May 09, 2014 5:18 pm
Contact:

first working example from Boriel’s ZXBasic Compiler, finally

Post by nitrofurano »

finally i could get a working zx81 code compiled from Boriel’s ZXBasic Compiler! :)

but i have some questions about:

1- i'm struggling to use functions that uses more than one argument, because they use ix and iy registers - when i try to use them the display gets totally blank (the functions i'm using are 'fastcall', that accesses simpler registers instead of ix and iy, but it is limited to one argument only) - why that happens? and how can i use ix and iy registers efficiently then?

2- where do i set sp (stack point) register?

3- which i/o ports are used for keyboard (is that exactly like ZX-Spectrum?), ay sound (like from quicksilva), and stuff like that?

thanks in advance! :)
Attachments
example02f_working.zip
(5.28 KiB) Downloaded 296 times
User avatar
nitrofurano
Posts: 24
Joined: Fri May 09, 2014 5:18 pm
Contact:

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by nitrofurano »

updated, i found out how the keyboard works
Attachments
example02h_working.zip
(7.32 KiB) Downloaded 317 times
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by PokeMon »

IX and IY registers are in use by the "system".
You may use these registers in FAST mode only and have to store old content and restore when your program finish.
But this way you have no display as it is used by the display routines.

I don't understand your question about SP - this is normally set automatically and no need to change.
If you do so you need more information about the compiler, memory areas and so.

If you are programming in C language it may be a better choice to use the z88dk Compiler which offers ZX81 drivers and allow the use of at least the IY register through an own display routine.
http://www.z88dk.org/forum/
User avatar
nitrofurano
Posts: 24
Joined: Fri May 09, 2014 5:18 pm
Contact:

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by nitrofurano »

thanks! my point about using Boriel’s ZXBasic Compiler is exactly for avoiding C! :D (due to laziness! :D) - and also, i were interested on sharing the idea of using such amazing cross-compiler as Boriel’s ZXBasic Compiler is, for developing stuff for ZX81

my doubt about stack point and ram sizes available were mostly because sz81 emulator, since there you can choose between 1kb, 2kb, 3kb, 4kb, 16kb, 32kb, 48b and 56kb (i didn’t test everything yet), and i imagine that the stack point address depends of the ram amount available, and the zx81 rom routines are unable to detect all of these possibilities

and thanks about the info related to ax and ay registers
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by PokeMon »

Yes - if the compiler creates an application it must be loaded somehow on the ZX81. Usually it can only read "BASIC programs" which may contain assembly code as well. As the stack pointer is initialized before a program is loaded (how else would you start LOAD "") I wouldn't care about changing the stack pointer manually.

If you are more familiar with assembly then you may use other tools as well. Don't know Boriel's language used.
In general if a program is called via the BASIC "usr" interface (RAND USR ...) you may use following registers:

AF
BC
DE
HL
BC'
DE'
HL' (has to be restored before returning to BASIC)
IY (may be used in FAST mode with display turned off but should be restored when returning)
IX (may be used in FAST mode with display turned off but should be restored when returning)
AF' (may be used in FAST mode with display turned off but should be restored when returning)
I (may be used in SLOW mode but disturbs the picture until restored)
R (unlikely to use for general applications)
16k memory (depending on ram extension)

If you need a temporary additional register using the stack with PUSH and followed by EX SP,(HL) is quite useful as well. This instruction swaps HL and top of stack and a second instruction changes back.

Good luck !
Last edited by PokeMon on Mon Mar 28, 2016 5:42 pm, edited 1 time in total.
User avatar
nitrofurano
Posts: 24
Joined: Fri May 09, 2014 5:18 pm
Contact:

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by nitrofurano »

thanks! :)

and btw, talking about ay sound, i tried this (quicksilva ports, i guess):

Code: Select all

out $7FFF,7
out $7FFE,$38
out $7FFF,0
out $7FFE,$FE
out $7FFF,8
out $7FFE,$0F
i tried to get a 440hz (A-4 from germanic notation) on channel a, with volume 15 (100%) - and there is no sound at all - what might be wrong there? i tried on sz81 emulator
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by Moggy »

I am not the brightest technically but this particular emulator uses the Zonx ports which I suspect are different to the quicksilva ones. Also remember to set the "unreal" option in the menu or some of the envelopes won't sound at all.

I find that this is the only emulator usable(for the ZX81)for tracker/compiler programs and it uses the correct Zonx frequency for the ZX81 as opposed to the spectrum Zonx frequency some emulators adopt and its output is near as dammit the real thing, so once you find the correct ports all should be well.

Hope this is of use. :)
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by sirmorris »

The IY register may also be used by a user program in slow mode if you can live with some restrictions.

1. You don't change its value

2. The area of memory you need to index over is restricted to something in the region $4000-$40FF. And only ~30 bytes in size, e.g. the printer buffer :)
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by PokeMon »

sirmorris wrote:2. The area of memory you need to index over is restricted to something in the region $4000-$40FF. And only ~30 bytes in size, e.g. the printer buffer :)
Well - this is not exactly true. The one byte displacement is a signed value which allows an offset only from -128 till +127. So you could address only $4000-$407F while in the area below $4000 mostly no memory is present. ;) But the printer buffer is accessible as all other system variables. Program area starts at $407D.
Two Index Registers (IX and IY)
The two independent index registers hold a 16-bit base address that is used
in indexed addressing modes. In this mode, an index register is used as a
base to point to a region in memory from which data is to be stored or
retrieved. An additional byte is included in indexed instructions to specify a
displacement from this base. This displacement is specified as a two's
complement signed integer. This mode of addressing greatly simplifies
many types of programs, especially where tables of data are used.
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: first working example from Boriel’s ZXBasic Compiler, finally

Post by sirmorris »

Well - this is not exactly true. The one byte displacement is a signed value which allows an offset only from -128 till +127.
:oops: Well you learn something new every day! :lol:
Post Reply