Help needed to start writing ZX81 games...

General games-related topics
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Help needed to start writing ZX81 games...

Post by bobs »

For the passed few years I've been coding Spectrum games with some success (see my website in the sig.) but feel like turning my hand back to a ZX81 for a game or two, like I did nearly 30 years ago.

Rather than writing it in BASIC on the ZX81 itself as I did then it would be good to be able to code it in Z80 on a PC and test it via an emulator - as I do my Spectrum stuff. I already have a development setup (GUI + complier), but I'm not familiar with the nuts'n'bolts of what's required to write code specificity for the ZX81, or which emulator to use.

Does anybody have an recommendations for an emulator, or links to articles regarding programming for the ZX81?
User avatar
thewiz
Posts: 58
Joined: Sun Aug 16, 2009 8:36 pm
Location: Crewe

Re: Help needed to start writing ZX81 games...

Post by thewiz »

Hi Bob, just had a look at your website and you have some seriously good looking games. I use eightyone 1.0a which probably the best emulator, http://www.chuntey.com/.

Have a look at Mastering Machine Code on your ZX81 by Toni Baker at http://www.worldofspectrum.org/infoseek ... id=2000236. Its what I used 25 years ago.

I've been doing a bit of zx81 1K development too recently and the code I write assembles to a .p file. It auto runs and its for an assembler called wla_dx.

Needs a batch file to run compile.

Code: Select all

wla_dx_9.4a\wla-z80 -oiv qfrog.asm qfrog.o
wla_dx_9.4a\wlalink -bisv qfrog.lk qfrog.p
The qfrog.lk files looks like

Code: Select all

[objects]
qfrog.o
The .p template follows

Code: Select all

; Character set

;  ____0___1___2___3___4___5___6___7___8___9___A___B___C___D___E___F____
;  00 SPC #_  _#  ##  __  #_  _#  ##  HH  __  HH   "  GBP  $   :   ?  0F
;         __  __  __  #_  #_  #_  #_  HH  HH  __

;  10  (   )   >   <   =   +   -   *   /   ;   ,   .   0   1   2   3  1F
;  20  4   5   6   7   8   9   A   B   C   D   E   F   G   H   I   J  2F
;  30  K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z  3F

; Keyboard matrix when reading LAST_K

; 
; LAST_K+1     FD  FB  F7  EF  DF | DF  EF  F7  FB  FD
;                                 |
; LAST_K                          |
; F7           1   2   3   4   5  | 6   7   8   9   0    EF
;                                 |
; FB           Q   W   E   R   T  | Y   U   I   O   P    DF
;                                 
; FD           A   S   D   F   G  | H   J   K   L  ret   BF
;                                 |
; FE               Z   X   C   V  | B   N   M   .  spc   7F

; Shift is bit 0 on LAST_K + 1.

; Setup for 1k .p file creation

.MEMORYMAP
	DEFAULTSLOT 0
	SLOT 0 START $4009 SIZE $3f7
.ENDME

.ROMBANKMAP
	BANKSTOTAL 1
	BANKSIZE $3f7
	BANKS 1
.ENDRO

.BANK 0 SLOT 0
.ORGA $4009

.ASCIITABLE
	MAP ' ' = 0
	MAP '"' = 11
	MAP '#' = 12
	MAP '$' = 13
	MAP ':' = 14
	MAP '?' = 15
	MAP '(' = 16
	MAP ')' = 17
	MAP '>' = 18
	MAP '<' = 19
	MAP '=' = 20
	MAP '+' = 21
	MAP '-' = 22
	MAP '*' = 23
	MAP '/' = 24
	MAP ';' = 25
	MAP ',' = 26
	MAP '.' = 27
	MAP '0' TO '9' = 28
	MAP 'A' TO 'Z' = 38
	MAP 'a' TO 'z' = 166	; Inverse letters
.ENDA

.SECTION "PFILE"

;
; Format of P file with no variables
;
; Need to flag locations used by Interrupt and used by Basic
;
	.EQU	ERR_NR	$4000
	.EQU	FLAGS	$4001
	.EQU	ERR_SP	$4002
	.EQU	RAMTOP	$4004
	.EQU	MODE	$4006
	.EQU	PPC	$4007
;
VERSN	.DB $00
E_PPC	.DW $0000
D_FILE	.DW DISPLAY		; Updated by display routine
DF_CC	.DW DISPLAY + 1
VARS	.DW VARAREA
DEST	.DW $0000
E_LINE	.DW VARAREA + 1
CH_ADD	.DW AUTO - 1		; Addr of EOL just run
X_PTR	.DW $0000
STKBOT	.DW VARAREA + 2
STKEND	.DW VARAREA + 2
BERG	.DB $00			; Updated by Basic
MEM	.DW $405D		; Updated by Basic
	.DB $00
DF_SZ	.DB $02
S_TOP	.DW $0000
LAST_K	.DW $FFFF		; Updated by display routine
DBOUNCE	.DB $00			; Updated by display routine
MARGIN	.DB $37			; Updated by display routine
NXTLIN	.DW AUTO		; Address of Next line to interpret
OLDPPC	.DW $0000
FLAGX	.DB $00			; Updated by Basic
STRLEN	.DW $0000
T_ADDR	.DW $0C8D		; Updated by Basic
SEED	.DW $0000
FRAMES	.DW $0000		; Updated by display routine
COORDS	.DW $0000
PR_CC	.DB $BC
S_POSN	.DB $21
	.DB $18
CDFLAG	.DB $40			; Updated by display routine
PRBUFF	.DS 32, 0		; Next 65 bytes available for M/C
	.DB $76
MEMBOT	.DS 30, 0
	.DW $0000
;
	.DB $76

; Basic program starts here. Each line ends with a $76.

; 0 RAND USR VAL "START"
; Shorter then 0 RAND USR START by two bytes.

AUTO	.DW 0				; Line number (MSB)
	.DW USREND - USRBEG		; Line length
USRBEG	.DB $f9, $d4, $c5, $0b		; RAND USR VAL "
	.DB (START / 10000) + $1c
	.DB ((START # 10000) / 1000) + $1c
	.DB (((START # 10000) # 1000) / 100) + $1c
	.DB ((((START # 10000) # 1000) # 100) / 10) + $1c
	.DB ((((START # 10000) # 1000) # 100) # 10) + $1c
	.DB $0b				; "
	.DB $76				; EOL
USREND

; Machine code starts here.
; No need for a REM statement, saving 6 bytes.

; Initialise system

START	ld hl, $4400			; Init MC stack	to top of memory
	ld sp, hl

; Horrible busywait checking for change of frame counter

	ld hl,FRAMES
	ld a,(hl)
-	cp (hl)
	jr z,-

; Machine code ends here.

; Pre defined display file.

DISPLAY	.DB $76

	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118
	.DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,118

	.DS 8, $76		; 8 lines of collapsed display. Replace

VARAREA	.DB $80

; Putting machine code here doesn't work. BASIC probably overwriting it.

.ENDS
I don't use any ROM routines to update the screen so it doesn't move about in memory and is always accessible from DISPLAY onwards.

Hope that helps to get you started.
Memotech rules
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Help needed to start writing ZX81 games...

Post by XavSnap »

Hi,
Ready to help you Bob !
:P
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Help needed to start writing ZX81 games...

Post by bobs »

Thanks for all the info TheWiz - I've downloaded the emulator and book, so that'll be a bit of light reading for the coming bank-holiday weekend, and I'll hopefully be able to get something basic up & running soon (I have a Spectrum project I need to get started soon also, hopefully juggle to two together)

On a similar vein, what's the score with hi-res graphics on a ZX81? I remember it being done with dedicated hardware at the time, and have read on these forums about doing it on a 1K machine, but what about a 16K machine - is it possible on a standard ZX81?
User avatar
thewiz
Posts: 58
Joined: Sun Aug 16, 2009 8:36 pm
Location: Crewe

Re: Help needed to start writing ZX81 games...

Post by thewiz »

As far as I am aware, its not possible to get hires on zx81 with 16K without hardware modification.
Memotech rules
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: Help needed to start writing ZX81 games...

Post by Moggy »

Hi Bobs

take care with toni bakers book riddled with errors, rom addresses in particular.
3 revisions within space of a year nuff said.

regards moggy
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: Help needed to start writing ZX81 games...

Post by RWAP »

thewiz wrote:As far as I am aware, its not possible to get hires on zx81 with 16K without hardware modification.
Now now - hi-res (or pseudo hi-res) is possible - think of the Software Farm programs - 256x192 pixel displays.
The Z80's i register pointed to a font table. You could move this around in the ROM to create swirly graphics effects. The game Astral Convoy did this. Unfortunately, the design of the ZX81 made it impossible for the character set to be anywhere in the 16K range, so you couldn't have a user defined set without extra hardware. With a 64K RAM pack you could disable the ROM shadow between 8K and 16K and design your own UDGs.

2. CRL released a Hi-Res graphics toolkit. This contained an extremely hairy interrupt routine that replaced the ZX81's usual display update routine. Basically, it pointed the i register to a strategic ROM location, and tried to 'best fit' the HRG display to what it could find in those locations. It also used a feature of the ZX81's hardware that allowed you to have 1 pixel height characters to improve it's chances.

You still could, at best, only have 128 different combinations out of the 256 possible ones. These were the 64 'characters' and their inverses. So this is really pseudo-HRG.

A number of games by Software Farm, including Hi-Res Invaders and Rocket Man, used this technique.
See also: http://www.zx81.nl/dload/unsorted/zx81hres.txt
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Help needed to start writing ZX81 games...

Post by bobs »

Moggy wrote:Hi Bobs

take care with toni bakers book riddled with errors, rom addresses in particular.
3 revisions within space of a year nuff said.

regards moggy
Thanks for the warning - but in skim-reading it last night I realised it was not really what I was after. I'm already very prolific in Z80, which much of the book is given over to covering, but am more looking for the particular nuts & bolts of programming the ZX81 in particular. For example, how the display file works (think I've picked that up from the manual though), keyboard input, port usage, any quirks regarding using certain registers (is it right that I can't use IX / IY?), differences in ROM versions - that sort of thing. I'm intending of writing in pure machine code for the 16K machine, and not use any ROM routines. Does anything like that already exist? If not, any information/links anybody can supply would be useful, and I'll gather it all together in a document for other users.

Also, looking back at TheWiz's post, what's the requirement for the .P file? I'm thinking it's the equivalent of a basic loader for the compiled machine code?

Sorry if these are all questions with obvious answers, but although I can program the ZX81 "natively" on the actual machine in BASIC, I've no idea about using it under an emulator with machine code.
User avatar
bobs
Posts: 325
Joined: Thu Aug 27, 2009 10:49 pm
Location: UK
Contact:

Re: Help needed to start writing ZX81 games...

Post by bobs »

RWAP wrote:Now now - hi-res (or pseudo hi-res) is possible - think of the Software Farm programs - 256x192 pixel displays.

See also: http://www.zx81.nl/dload/unsorted/zx81hres.txt
It was the Software Farm stuff I was thinking of, and that link was very useful, thanks! I think to begin with I'll stick with using the standard character-mapped display - it has a certain charm to me - but maybe one day...
Moggy
Posts: 3266
Joined: Wed Jun 18, 2008 2:00 pm

Re: Help needed to start writing ZX81 games...

Post by Moggy »

Hi Bobs

One useful book to look out for is ASSEMBLY LANGUAGE ASSEMBLED FOR THE SINCLAIR ZX81.by Anthony Woods, pops up from time to time on e-bay. Explains use of ix and iy ,though neglects to mention that the zeddy should be in fast mode at the time!!! Written to be used with BUG-BYTES ZXAS assembler, available as a p file on most zeddy software sites (look for the ts 1000 version ZXAS(GE) as the BUG-BYTE version tends to give error reports for perfectly valid code at assembly time.) A good book for the hardware side of things port usage etc is THE INS AND OUTS OF THE TIMEX TS 1000 AND ZX81 by Don Thomasson available, last time I looked ,from THE SINCLAIR SHOP on e-bay, and Ian Logans book UNDERSTANDING YOUR ZX81 ROM explains port instructions Rom differences (Bugs in the floating point calculator, 0.25^2 gives 3.1423844, as opposed to the correct answer of 0.0625 on the early rom) etc in some detail. I have both types of rom and three different ula versions there could be more .

Hope this is useful regards Moggy
Post Reply