ZX81 Assembly Programming - Getting Started

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
swensont
Posts: 61
Joined: Tue Jan 18, 2011 4:55 am
Location: SF Bay Area

ZX81 Assembly Programming - Getting Started

Post by swensont »

A few months ago, I returned to doing a little ZX81 assembly programming after almost 25 years gone. In learning about the new tools and new emulators, I found no single "Getting Started" document, so I decided to create one.

The paper is called "Assembly Language on the ZX81: An Updated Getting Started Guide". There are number of books that instruct the new user on assembly language on the ZX81. This document adds additional information about doing the assembly language with emulators and cross compilers. The paper provides some examples of short assembly programs (fully tested) using the TASM cross assembler and an appendix lists a number of ZX81 rom routines and how they are used.

I'm no expert on the subject, but I find that when I document something that I am learning, I learn it much better. I know that quite a number of folks on the Board are experts at assembly and I don't know if there are any people interested in learning, but at least the document is done and maybe someone will find it useful.

The document was too large for the Board, so Rich hosted it for me:

http://www.rwapsoftware.co.uk/zx81/ZX81 ... tarted.zip

Tim Swenson

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

Re: ZX81 Assembly Programming - Getting Started

Post by sirmorris »

Excellent stuff! It's beautifully produced - really professional! I'm going to have a thorough read of the ROM section and see what I can learn :D

One thing you may not be aware of is that TASM is incompatible with 64 bit OSes. I switched from TASM to PASMO for the ZXpand firmware. It will eat tasm code pretty well untouched, but like all assemblers you have to watch out for the wrinkles. A listing file is always recommended ;)

User avatar
gus
Posts: 177
Joined: Fri May 16, 2008 10:18 pm
Location: Buenos Aires. Argentina
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by gus »

Hi Tim

Very nice document and like Sir Morris tells you, a very professional look ! It's good to have new documentation on this matter.
BTW: I use PASMO too, because it runs on Linux 64 and comes with source code.

Thanks for your good work.

Gus

User avatar
bobs
Posts: 278
Joined: Thu Aug 27, 2009 10:49 pm
Location: Derbyshire, UK
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by bobs »

Very nice document. I have felt about writing one myself, given that like you I couldn't find anything online which was easily accessible when I started to write for the 81 last year. I think I can cover a few things which you haven't though, but I won't be able to match your excellent presentation - txt documents only for me!

swensont
Posts: 61
Joined: Tue Jan 18, 2011 4:55 am
Location: SF Bay Area

Re: ZX81 Assembly Programming - Getting Started

Post by swensont »

Thanks for the feedback. The whole thing was done in OpenOffice with layout done with Scribus. GIMP was used for the front graphics and Irfanview for the internal graphics. (All the programs are either OpenSource or freeware) Since I've worked with Scribus for about 5 years, it was pretty easy to do the layout and make it look nice.

If people have additional sections to add, I can add them. Full credit will go to those authors. I can take pure text, test any code, and spruce it all up.

There were some parts that I had planned but did not have the time or knowledge. It would be interesting to know how to call the math functions (SQR, COS, etc) from assembly.

The next thing that needs to be documented is how to do WRX16K hi-res graphics programming. I've seen the documentation on the web, but it does not have any working examples of how to get it working. There are some WRX16K enabled programs with source code available, but they are not the easiest to read and understand. We need some nice "hello, world" programs for hi-res.

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

Re: ZX81 Assembly Programming - Getting Started

Post by Moggy »

swensont wrote:
There were some parts that I had planned but did not have the time or knowledge. It would be interesting to know how to call the math functions (SQR, COS, etc) from assembly.
Try this link Swensont it's a corrected pdf version by Thunor of, mastering machine code on Your zx81. The link takes You to the relevent section.
The original book was fairly bug ridden ,even after three revisions, incorrect rom addresses etc, but, after a heads up from Myself about this and other errors Thunor toiled away to produce what the book should have been in the first place.
He has left the incorrect text in situ but struck out; and the only omission I can see is the 81's calculator code for raising of powers (6), although the original author provides a slighty long winded alternative, also missing is the routine to print a floating point number off the top of the stack ( improved rom address 2913 decimal); read the text and You will see what I mean.

The calculator routines can also use other functions like peek, chr$, not etc, but whilst it's fun to use in assembler You will find it runs no faster , in practical terms, than Basic due, in part, to the housekeeping and error checking it goes through. For integer work Just Google for any of the standard z80 maths routines out there , and use the calculator for floating point work only, or try Forth for Maths (very fast and easy to learn plus if You want to use the calculator You need a grounding in forth anyway ). ;)

Hope this helps :D
Regards Moggy

http://www.users.waitrose.com/~thunor/m ... ter17.html

fabionm
Posts: 1
Joined: Sun May 01, 2011 11:55 pm

Re: ZX81 Assembly Programming - Getting Started

Post by fabionm »

Hi Man, thanks for your article.
I have some doubts. about the syntax of the templates below. Could you show some examples?
line0.asm
line1.asm
charcode.asm
sysvars.asm

THe tasm creates a REM line if my code starts 16514 address?

Thanks a lot

Fabio (BRASIL)

User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

Hi !

I'm a happy new user of this forum. I had a ZX81 when i was 10 years old \o/

I'm very happy to find this documentation to (re)start discover my ZX81.

Lot of samples, great !

But in the zip archive there miss files like :

line0.asm
line1.asm
sysvars.asm
charcode.asm

Normal or i don't understand something ?!

I mean that "an example was good to understand the use of these files" ^^

Thanks.
-=Zac

User avatar
Zac
Posts: 25
Joined: Wed Oct 31, 2012 11:28 am
Location: Montpellier / FRANCE \o/
Contact:

Re: ZX81 Assembly Programming - Getting Started

Post by Zac »

After little research on internet i finally arrive to make my first ASM program compiled with TASM. I'm not sure it's full optimised... What you think about ?

Code: Select all

; Zac test ASM program #1
; (c) 2012 Zac
;

#define         DEFB .BYTE
#define         DEFW .WORD
#define         DEFM .TEXT
#define         ORG  .ORG
#define         EQU  .EQU

; ===========================================================
; Start of the Program
; ===========================================================

; Origin of a ZX81 file is always 16393

                ORG 16393
                
; System variables.

VERSN:          DEFB 0
E_PPC:          DEFW 2
D_FILE:         DEFW Display
DF_CC:          DEFW Display+1                  ; First character of display
VARS:           DEFW Variables
DEST:           DEFW 0
E_LINE:         DEFW BasicEnd 
CH_ADD:         DEFW BasicEnd+4                 ; Simulate SAVE "X"
X_PTR:          DEFW 0
STKBOT:         DEFW BasicEnd+5
STKEND:         DEFW BasicEnd+5                 ; Empty stack
BREG:           DEFB 0
MEM:            DEFW MEMBOT
UNUSED1:        DEFB 0
DF_SZ:          DEFB 2
S_TOP:          DEFW $0002                      ; Top program line number
LAST_K:         DEFW $FDBF
DEBOUN:         DEFB 15
MARGIN:         DEFB 55
NXTLIN:         DEFW Line2                      ; Next line address
OLDPPC:         DEFW 0
FLAGX:          DEFB 0
STRLEN:         DEFW 0
T_ADDR:         DEFW $0C8D
SEED:           DEFW 0
FRAMES:         DEFW $F5A3
COORDS:         DEFW 0
PR_CC:          DEFB $BC
S_POSN:         DEFW $1821
CDFLAG:         DEFB $40
PRBUFF:         DEFB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,$76 ; 32 Spaces + Newline
MEMBOT:         DEFB 0,0,0,0,0,0,0,0,0,0,$84,$20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; 30 zeros
UNUNSED2:       DEFW 0

; End of system variables

Program:        
Line1:          DEFB $00,$01                    ; Line 1
                DEFW Line1End-Line1Text         ; Line 1 length
Line1Text:      DEFB $EA                        ; REM             
   
; ===========================================================
; Insert your program here....
; ===========================================================

			LD 		A,1 				; start with 1
loop:										; label used for jump
			RST		10		 			; PRINT 
			INC		A 					; increment A
			CP 		36 					; stop at 36
			JP 		NZ,loop			; if not 36, then goto/jump to LOOP
			RET 							; Return to BASIC

; Programme équivalent en Basic
; 10 LET A = 1
; 20 PRINT CHR$(A)
; 30 LET A = A + 1
; 40 IF A <> 36 THEN GOTO 20
; 50 STOP

; ===========================================================
; That's it.  End of user program
; ===========================================================

                DEFB $76                        ; Newline
Line1End:       
Line2:          DEFB $00,$02                    ; Line 2
                DEFW Line2End-Line2Text
Line2Text:      DEFB $F9,$D4                    ; RAND USR
                DEFB $1D,$22,$21,$1D,$20        ; 16514
                DEFB $7E                        ; Number
                DEFB $8F,$01,$04,$00,$00        ; Numeric encoding
                DEFB $76                        ; Newline
Line2End: 

Display:        DEFB $76                        ; Newline
                DEFB $76 ; Line 0
                DEFB $76 ; Line 1
                DEFB $76 ; Line 2
                DEFB $76 ; Line 3
                DEFB $76 ; Line 4
                DEFB $76 ; Line 5
                DEFB $76 ; Line 6
                DEFB $76 ; Line 7
                DEFB $76 ; Line 8
                DEFB $76 ; Line 9 
                DEFB $76 ; Line 10
                DEFB $76 ; Line 11
                DEFB $76 ; Line 12
                DEFB $76 ; Line 13
                DEFB $76 ; Line 14
                DEFB $76 ; Line 15
                DEFB $76 ; Line 16
                DEFB $76 ; Line 17
                DEFB $76 ; Line 18
                DEFB $76 ; Line 19
                DEFB $76 ; Line 20
                DEFB $76 ; Line 21
                DEFB $76 ; Line 22
                DEFB $76 ; Line 23

; Variables area (empty)
Variables:      
VariablesEnd:   DEFB $80
BasicEnd:                              
                      
#END
-=Zac

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

Re: ZX81 Assembly Programming - Getting Started

Post by sirmorris »

Looks good!

One thing to consider is the following saying:

"Optimise in haste, repent at leisure"

Which simply says that you shouldn't worry about making things 'optimal' until you have a need to do so! If you worry about making everything optimal at every step then you'll never finish a program ;)

C

Post Reply