Berch's assembler

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
floydbloke
Posts: 12
Joined: Fri Oct 10, 2008 7:21 am
Location: Wellington, New Zealand

Re: Berch's assembler

Post by floydbloke »

Great templates sirmorris, thanks.

Quick question,is there any way to append lines of basic code to the .P file.

Or alternatively, what is the most suitable to load some machine code, followed by loading some basic. Do I need to set the RAMTOP and shift my machine code up there?

sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Berch's assembler

Post by sirmorris »

What usually happens is that any required machine code is dumped above RAMTOP. It's possible to do this in one operation, without the need for a double load, but I don't know what you'd gain.

What's the application? A toolkit that is expected to live across a number of program loads?

Tell me exactly what you have in mind - there's a few other options to consider too..!

floydbloke
Posts: 12
Joined: Fri Oct 10, 2008 7:21 am
Location: Wellington, New Zealand

Re: Berch's assembler

Post by floydbloke »

I'm trying to write a simple game which will end up being standalone in machine code, no basic required.

My request is because I'm simply being lazy during testing/debugging, and don't want to retype every time I re-assemble and re-load the P file. About 6 lines of basic that take user input to POKE an adress,and then a for next loop to PEEK a sequence of addresses.

Also handy to know for future reference of course.

sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Berch's assembler

Post by sirmorris »

Hmm.

It'd be hacky but what I'd do is the following:

Write the basic, without the REM, in EO. (must be v1.0a)
Type PRINT PEEK 16396 + 256 * PEEK 16397 - 16509
This gives the length of the basic program.
Save a memory block from 16509 with the length calculated above.
View the saved memory in a hex editor or other tool to see the raw bytes for example:

Code: Select all

00 0A 05 00 F5 0B 35 0B 76 00 14 03 00 EE 34 76 00 1E 0F 00 F4 1D 22 21 1D 20 7E 8F 01 04 00 00 1A 34 76
Process the raw hex and replace the code in line1.asm like so:

Code: Select all

;= Second BASIC line, calls ASM ==================================

line1:
   .byte $00,$0A,$05,$00,$F5,$0B,$35,$0B
   .byte $76,$00,$14,$03,$00,$EE,$34,$76
   .byte $00,$1E,$0F,$00,$F4,$1D,$22,$21
   .byte $1D,$20,$7E,$8F,$01,$04,$00,$00
   .byte $1A,$34,$76

;- Collapsed display file --------------------------------------------
This would work well for longer BASIC programs, but for one or two lines I'd spend some time with no$'s zx81 docs and just work out what the line should be in raw token form, much like in the template.

I've just checked the output in EO and it appeared as if the template I posted wasn't working - the line 1 REM was fouling up. Have I gone insane? No - I think it was because there was not much data in the rem line... Adding some padding made it work as expected. Can anyone confirm this? Xav?

floydbloke
Posts: 12
Joined: Fri Oct 10, 2008 7:21 am
Location: Wellington, New Zealand

Re: Berch's assembler

Post by floydbloke »

Thanks to sirmorris' templates, a stunning emulator and a scanned PDF of 'Mastering Machine Code on your ZX81' I've managed to cobble together my first assembly language program so I thought I'd share it. A simple game, based on the Casio mg-888 game-calculator of the same era as the zeddy, of chance where you have to try and wipe out all the numbers by selecting them. The total of the selection should equal the total of the dice, then newline wipes the numbers and rolls the dice again. Depending on the option selected at the start, you can pass if the total can't be made with the numbers left on the board (or you can pass any time you like). 0 to clear your selection if you've made an error.
DICE.P
(3.91 KiB) Downloaded 105 times
And here's the code if anyone is really bored. I expect it's horribly sloppy and inefficient (e.g. using whole bytes to check true/false states instead of single bits) but I don't have the energy or motivation (on to the next 'project') to do any optimisation. In saying that, if anyone spots any glaring errors or opportunities for improvement or enhancements I'm keen to hear it.
dicegame.asm
(26.46 KiB) Downloaded 128 times

Moggy
Posts: 1990
Joined: Wed Jun 18, 2008 2:00 pm

Re: Berch's assembler

Post by Moggy »

Hi floydbloke

nice game cant wait for your next project. i noticed in an earlier post that you might use
zxas as your assembler if so use this link and download zxas(ge) for the ts1000, it doesn't have the bugs of the original zxas (ie error reports and non compilation of perfectly legal instructions).

http://www.zx81stuff.org.uk/zx81/indexframes.html

Also mastering machine code on your zx81 is iffy in places (addresses for the calculator routines are a bit out) depending on which revision of the book you have.

hope this is of use
all the best ,moggy

User avatar
zx81jens
Posts: 190
Joined: Sat May 10, 2008 8:26 am
Location: a Basement in Nienburg / Germany

Re: Berch's assembler

Post by zx81jens »

hi users!

the original file

viewtopic.php?f=6&t=133&p=1009&hilit=TEMPER.ZIP#p1009

is gone in the crash...

does anybody have the .zip-file? can you post it here again?

that would be nice!

greetings
jens
eyerything will be okay in the end.
if it´s not okay, it´s not the end.

and: uıɐbɐ ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ɹǝʌǝ ɹǝʌǝu ןןıʍ ı

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

Re: Berch's assembler

Post by RWAP »

In fact all the files from this thread are missing - including the assembler itself and the dice game files.

Oddly I have no recollection of ever having read this thread before!

Where is floydbloke when you need him ?

sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: Berch's assembler

Post by sirmorris »

Here's the template:

Code: Select all

; TASM cross-assembler definitions
;
#define	db		.byte
#define	dw		.word
#define	ds		.block
#define	org	.org
#define	end	.end

; A useful reference
;
;  ____0___1___2___3___4___5___6___7___8___9___A___B___C___D___E___F____
;  00 SPC GRA GRA GRA GRA GRA GRA GRA GRA GRA GRA  "  GBP  $   :   ?  0F
;  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


	; -------------=-=-=-=-=-=-=-=-=-=-=-------------
	;               ASSEMBLER  TEMPLATE
	; -------------=-=-=-=-=-=-=-=-=-=-=-------------


			org	$4009

ERR_NR	.equ	$4000
FLAGS		.equ	$4001
ERR_SP	.equ	$4002
RAMTOP	.equ	$4004
MODE		.equ	$4006
PPC		.equ	$4007

; System variables as saved to tape

VERSN:	db		0
E_PPC:	dw		0
D_FILE:	dw		dfile
DF_CC:	dw		dfile+1
VARS:		dw		var
DEST:		dw		0
E_LINE:	dw		var+1
CH_ADD:	dw		last-1
X_PTR:	dw		0
STKBOT:	dw		last
STKEND:	dw		last
BERG:		db		0
MEM:		dw		MEMBOT
			db		0
DF_SZ:	db		2
S_TOP:	dw		1
LAST_K:	db		$FF,$FF,$FF
MARGIN:	db		55
NXTLIN:	dw		line1
OLDPPC:	dw		0
FLAGX:	db		0
STRLEN:	dw		0
T_ADDR:	dw		$0C8D
SEED:		dw		0
FRAMES:	dw		$FFFF
COORDS:	db		0,0
PR_CC:	db		$BC
S_POSN:	db		33,24
CDFLAG:	db		01000000B
PRTBUF:	ds		33			; print buffer - iow scratch ram for us :)
MEMBOT:	ds		30			; calculator's scratch
			ds		2

line0:
	db		$00,$00		; line number
	dw		line1-$-2	; line length

	db		$ea			; REM

	db		$7e			; m/c for ld a,(hl),  BASIC token for 'next 5 bytes are fp number'
	jp		go				; 3 bytes
	db		0,0			; +2 bytes ... this effectively hides the m/c in the REM


	; -------------=-=-=-=-=-=-=-=-=-=-=-------------


go:

	;;;; PUT CODE HERE :)

	ret

 

	db		$76							; N/L - end of line 0


line1:
	db		0,1   						; line number
	dw		dfile-$-2					; line length

	db		$f9,$d4,$c5					; RAND USR VAL
	db		$b,$1d,$22,$21,$1d,$20,$b	; "16514"

	db		$76    						; N/L - end of line 1


;- Display file --------------------------------------------

dfile:
	db		$76
	db		$76,$76,$76,$76,$76,$76,$76,$76
	db		$76,$76,$76,$76,$76,$76,$76,$76
	db		$76,$76,$76,$76,$76,$76,$76,$76


;- BASIC-Variables ----------------------------------------

var:
	db		$80


;- End of program area ----------------------------

last:
	end
It _should_ work as I've edited it from a working project, but you never know.

C

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

Re: Berch's assembler

Post by RWAP »

I have re-uploaded the Assembler / Disassembler written by Bob Berch as referred to by floydbloke.

Indeed, there are a total of four versions files available (not sure of the differences). The first two are for 16K, the other two are for 32K machines:

Post Reply