ZX81CRSS.ASM

Discussion about ZX80 / ZX81 Software
Bill H
Posts: 163
Joined: Sat Nov 27, 2010 6:05 pm

ZX81CRSS.ASM

Post by Bill H »

I have rebuilt my original cross assembler file I had on ts1000.us using an original from Zeddy-br and cleaned it up and added a lot of comments. This makes it very easy to create self running machine language programs for the TS1000 (ZX81).

Bill H (Milli)

Code: Select all

; ZX81CRSS.ASM
;
; This file will allow you to compile z80 code directly to a .P file that
; can be loaded into one of the various ZX81 / TS 1000 emulators. To use
; add your code wher it says "Put your code here", compile and load.
;
; To compile use the Telemark assembler:
;
; TASM -b -80 zx81crss.asm zx81crss.p
;
; William Hicks
;
; Recreated in 03/2018 from code written by Zeddy-Br in 08/2005

               .org    16393

VERSN          .db 0                   ; 0 Identifies ZX81 BASIC in saved programs
E_PPC          .dw 0                   ; Number of current line (with program cursor)
D_FILE         .dw R_DFILE             ; Address of Display File (screen data) in memory
DF_CC          .dw R_DFILE + 1         ; Address of PRINT position in display file
                                       ; Can be poked so that PRINT output is sent elsewhere
VARS           .dw R_VARS              ; Address of user program variables in memory
DEST           .dw 0                   ; Address of variable in assignment
E_LINE         .dw R_E_LINE            ; Address of line being editted in memory
CH_ADD         .dw R_LAST - 1          ; Address of the next character to be interpreted:
                                       ; the character after the argument of PEEK, or the
                                       ; NEWLINE at the end of a POKE statement
X_PTR          .dw 0                   ; Address of the character preceding the [S] marker
STKBOT         .dw R_STKBOT            ; Address of the Calculator stack in memory.
                                       ; This is where Basic does the math calculations
STKEND         .dw R_STKBOT            ; End of the Calculator stack
BERG           .db 0                   ; Calculator's b register
MEM            .dw MEMBOT              ; Address of area used for calculator's memory.
                                       ; (Usually MEMBOT, but not always.)
               .db 0                   ; Not Used
DF_SZ          .db 2                   ; The number of lines (including one blank line)
                                       ; in the lower part of the screen.
S_TOP          .dw 1                   ; The number of the top program line in automatic listings
LAST_K         .db 0ffh,0ffh           ; Shows which keys pressed
               .db 0ffh                ; Debounce status of the keyboard
MARGIN         .db 55                  ; Number of blank lines above or below picture:
                                       ; 55 in Britain, 31 in America

; Make NXTLIN equal Line_10 if you want the code to autorun,
; or make it equal R_DFILE if you do not want it to autorun

NXTLIN         .dw Line_10             ; Address of next program line to be executed

OLDPPC         .dw 0                   ; Line number of which CONT jumps
FLAGX          .db 0                   ; Various flags
STRLEN         .dw 0                   ; Length of string type destination in assignment
T_ADDR         .dw 0c8dh               ; Address of next item in syntax table (very unlikely to be useful)
SEED           .dw 0                   ; The seed for RND. This is the variable that is set by RAND
FRAMES         .dw 0ffffh              ; Counts the frames displayed on the television.
                                       ; Bit 15 is 1. Bits 0 to 14 are decremented for each frame
                                       ; set to the television. This can be used for timing, but
                                       ; PAUSE also uses it. PAUSE resets to 0 bit 15, & puts in
                                       ; bits 0 to 14 the length of the pause. When these have been
                                       ; counted down to zero, the pause stops. If the pause stops 
                                       ; because of a key depression, bit 15 is set to 1 again.
COORDS         .db 0                   ; x-coordinate of last point PLOTted
               .db 0                   ; y-coordinate of last point PLOTted
PR_CC          .db 0bch                ; Less significant byte of address of next position for
                                       ; LPRINT to print as (in PRBUFF)
S_POSN         .db 33                  ; Column number for PRINT position
               .db 24                  ; Line number for PRINT position
CDFLAG         .db 01000000b           ; Various flags. Bit 7 is on (1) during compute & display mode
PRBUFF         .fill 33,0              ; Printer buffer
MEMBOT         .fill 30,0              ; Calculator's memory area; used to store numbers that cannot
                                       ; conveniently be put on the calculator stack
               .dw 0                   ; Not Used

Line_0:
               .db 0,0                 ; line number
               .dw Line_10 - $ - 2     ; line length
               .db 0eah                ; REM

; *********************************
; Put your code here. Do not use
; the Z80 HALT instruction as the
; ZX81 will see it as a NEWLINE
; and it could cause your program
; crash (maybe).
; *********************************

               ret

; *********************************
; Do not change anything after this
; *********************************

               .db 076h                ; NEWLINE

Line_10:
               .db 0,10                ; line number
               .dw R_DFILE - $ - 2     ; line length
               .db 0f9h                ; RAND
               .db 0d4h                ; USR
               .db 01dh                ; 1
               .db 022h                ; 6
               .db 021h                ; 5
               .db 01dh                ; 1
               .db 020h                ; 4
               .db 07eh                ; FP mark
               .db 08fh                ; 5 bytes FP number
               .db 001h                ;
               .db 004h                ;
               .db 000h                ;
               .db 000h                ;
               .db 076h                ; NEWLINE

R_DFILE        .fill 25,076h           ; Compacted D_FILE (25 NEWLINE's)
R_VARS
               .db 080h                ; End of Variables Marker
R_E_LINE
R_STKBOT
R_LAST
               .end
Attachments
zx81crss.asm
TASM ZX 81 Assembly file.
(6.17 KiB) Downloaded 305 times
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81CRSS.ASM

Post by XavSnap »

Thanks Bill,

I wonder if it will be possible to put the 10 line (RAND USR) in the printer buffer, and assign the NXT_line to the prt buffer!

Fill a mirrored DF_File next, and jump to you ASM after the Dfile.

But, the basic will crash on the RET function...
It can allow a full memory asm code (after the PRTbuffer) on a single file, and save room in the basic/vars location.
:oops:
Anyone test this attic code structure?
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
sirmorris
Posts: 2811
Joined: Thu May 08, 2008 5:45 pm

Re: ZX81CRSS.ASM

Post by sirmorris »

I think Dr. Beep is quite brutal in his use of all the free memory locations, it's not something I've tried though. But perhaps in this case that's missing the point - this is supposed to be a nice easily understood starter project for people 8-)
Bill H
Posts: 163
Joined: Sat Nov 27, 2010 6:05 pm

Re: ZX81CRSS.ASM

Post by Bill H »

XavSnap wrote: Wed Mar 14, 2018 8:24 pm I wonder if it will be possible to put the 10 line (RAND USR) in the printer buffer, and assign the NXT_line to the prt buffer!
I believe back in '05 we discussed using the print buffer and that it is nulled out when you load the program. Putting ML code outside of the the program lines get clobbered to if I remember right.

Now I need to find a list of ROM entry points or the ROM source code.

Bill H
Bill H
Posts: 163
Joined: Sat Nov 27, 2010 6:05 pm

Re: ZX81CRSS.ASM

Post by Bill H »

Answered my own question on the zx81 rom source code

https://raw.githubusercontent.com/tom-s ... s/zx81.txt

Bill H
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81CRSS.ASM

Post by XavSnap »

In your TASM main code:

Code: Select all

#include ZX81.sym
rename "ZX81.sym.txt" to "ZX81.sym"
ZX81.sym.txt
(15.5 KiB) Downloaded 321 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81CRSS.ASM

Post by XavSnap »

:shock:

:?: :?: :?: :?:

It working...

The RAND USR was moved in the PRT_buffer !

Code: Select all

; ZX81CRSS.ASM
;
; This file will allow you to compile z80 code directly to a .P file that
; can be loaded into one of the various ZX81 / TS 1000 emulators. To use
; add your code wher it says "Put your code here", compile and load.
;
; To compile use the Telemark assembler:
;
; TASM -b -80 zx81crss.asm zx81crss.p
;
; William Hicks
;
; Recreated in 03/2018 from code written by Zeddy-Br in 08/2005

;#include ZX81.sym

               .org    16393

VERSN          .db 0                   ; 0 Identifies ZX81 BASIC in saved programs
E_PPC          .dw 0                   ; Number of current line (with program cursor)
D_FILE         .dw R_DFILE             ; Address of Display File (screen data) in memory
DF_CC          .dw R_DFILE + 1         ; Address of PRINT position in display file
                                       ; Can be poked so that PRINT output is sent elsewhere
VARS           .dw R_VARS              ; Address of user program variables in memory
DEST           .dw 0                   ; Address of variable in assignment
E_LINE         .dw R_E_LINE            ; Address of line being editted in memory
CH_ADD         .dw R_LAST - 1          ; Address of the next character to be interpreted:
                                       ; the character after the argument of PEEK, or the
                                       ; NEWLINE at the end of a POKE statement
X_PTR          .dw 0                   ; Address of the character preceding the [S] marker
STKBOT         .dw R_STKBOT            ; Address of the Calculator stack in memory.
                                       ; This is where Basic does the math calculations
STKEND         .dw R_STKBOT            ; End of the Calculator stack
BERG           .db 0                   ; Calculator's b register
MEM            .dw MEMBOT              ; Address of area used for calculator's memory.
                                       ; (Usually MEMBOT, but not always.)
               .db 0                   ; Not Used
DF_SZ          .db 2                   ; The number of lines (including one blank line)
                                       ; in the lower part of the screen.
S_TOP          .dw 1                   ; The number of the top program line in automatic listings
LAST_K         .db 0ffh,0ffh           ; Shows which keys pressed
               .db 0ffh                ; Debounce status of the keyboard
MARGIN         .db 55                  ; Number of blank lines above or below picture:
                                       ; 55 in Britain, 31 in America

; Make NXTLIN equal Line_10 if you want the code to autorun,
; or make it equal R_DFILE if you do not want it to autorun

NXTLIN         .dw Line_10             ; Address of next program line to be executed

OLDPPC         .dw 0                   ; Line number of which CONT jumps
FLAGX          .db 0                   ; Various flags
STRLEN         .dw 0                   ; Length of string type destination in assignment
T_ADDR         .dw 0c8dh               ; Address of next item in syntax table (very unlikely to be useful)
SEED           .dw 0                   ; The seed for RND. This is the variable that is set by RAND
FRAMES         .dw 0ffffh              ; Counts the frames displayed on the television.
                                       ; Bit 15 is 1. Bits 0 to 14 are decremented for each frame
                                       ; set to the television. This can be used for timing, but
                                       ; PAUSE also uses it. PAUSE resets to 0 bit 15, & puts in
                                       ; bits 0 to 14 the length of the pause. When these have been
                                       ; counted down to zero, the pause stops. If the pause stops 
                                       ; because of a key depression, bit 15 is set to 1 again.
COORDS         .db 0                   ; x-coordinate of last point PLOTted
               .db 0                   ; y-coordinate of last point PLOTted
PR_CC          .db 0bch                ; Less significant byte of address of next position for
                                       ; LPRINT to print as (in PRBUFF)
S_POSN         .db 33                  ; Column number for PRINT position
               .db 24                  ; Line number for PRINT position
CDFLAG         .db 01000000b           ; Various flags. Bit 7 is on (1) during compute & display mode
PRBUFF         

Line_10:
               .db 0,10                ; line number
               .dw R_DFILE - $ - 2     ; line length
               .db 0f9h                ; RAND
               .db 0d4h                ; USR
               .db 01dh                ; 1
               .db 022h                ; 6
               .db 021h                ; 5
               .db 01dh                ; 1
               .db 020h                ; 4
               .db 07eh                ; FP mark
               .db 08fh                ; 5 bytes FP number
               .db 001h                ;
               .db 004h                ;
               .db 000h                ;
               .db 000h                ;
               .db 076h                ; NEWLINE
END0_LINE
	.fill 33-(END0_LINE-Line_10),0              ; Printer buffer



MEMBOT         .fill 30,0              ; Calculator's memory area; used to store numbers that cannot
                                       ; conveniently be put on the calculator stack
               .dw 0                   ; Not Used

Line_0:
               .db 0,0                 ; line number
               .dw Line_10 - $ - 2     ; line length
               .db 0eah                ; REM

; *********************************
; Put your code here. Do not use
; the Z80 HALT instruction as the
; ZX81 will see it as a NEWLINE
; and it could cause your program
; crash (maybe).
; *********************************
START:
	call $a2a 
	ld BC,$0707  
	call $8f5 
	ld BC,ENDTEXT-TEXT1 
	ld DE,TEXT1  
	call $b6b
        ret
TEXT1:
	.db H,E,L,L,O, ,W,O,R,L,D
ENDTEXT:

; *********************************
; Do not change anything after this
; *********************************

               .db 076h                ; NEWLINE


R_DFILE        .fill 25,076h           ; Compacted D_FILE (25 NEWLINE's)
R_VARS
               .db 080h                ; End of Variables Marker
R_E_LINE
R_STKBOT
R_LAST
               .end

A	.equ $26
B	.equ $27
C	.equ $28
D	.equ $29
E	.equ $2A
F	.equ $2B
G	.equ $2C
H	.equ $2D
I	.equ $2E
J	.equ $2F
K	.equ $30
L	.equ $31
M	.equ $32
N	.equ $33
O	.equ $34
P	.equ $35
Q	.equ $36
R	.equ $37
S	.equ $38
T	.equ $39
U	.equ $3A
V	.equ $3B
W	.equ $3C
X	.equ $3D
Y	.equ $3E
Z	.equ $3F

AUTOBOOT.P
(178 Bytes) Downloaded 282 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Bill H
Posts: 163
Joined: Sat Nov 27, 2010 6:05 pm

Re: ZX81CRSS.ASM

Post by Bill H »

Sweet!
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81CRSS.ASM

Post by XavSnap »

A simply auto-load in ASM.

0 RAND USR 16464 << Hidden
0 REM [44bytes] << Hidden

0 REM datas
(in basic, a LIST ou a LLIST will erase the ASM program in the PRT_Buffer!)

Amazing! 44 bytes saved !
:lol:

Code: Select all

; ZX81CRSS.ASM
;
; This file will allow you to compile z80 code directly to a .P file that
; can be loaded into one of the various ZX81 / TS 1000 emulators. To use
; add your code wher it says "Put your code here", compile and load.
;
; To compile use the Telemark assembler:
;
; TASM -b -80 zx81crss.asm zx81crss.p
;
; William Hicks
;
; Recreated in 03/2018 from code written by Zeddy-Br in 08/2005

;#include ZX81.sym

               .org    16393

VERSN          .db 0                   ; 0 Identifies ZX81 BASIC in saved programs
E_PPC          .dw 0                   ; Number of current line (with program cursor)
D_FILE         .dw R_DFILE             ; Address of Display File (screen data) in memory
DF_CC          .dw R_DFILE + 1         ; Address of PRINT position in display file
                                       ; Can be poked so that PRINT output is sent elsewhere
VARS           .dw R_VARS              ; Address of user program variables in memory
DEST           .dw 0                   ; Address of variable in assignment
E_LINE         .dw R_E_LINE            ; Address of line being editted in memory
CH_ADD         .dw R_LAST - 1          ; Address of the next character to be interpreted:
                                       ; the character after the argument of PEEK, or the
                                       ; NEWLINE at the end of a POKE statement
X_PTR          .dw 0                   ; Address of the character preceding the [S] marker
STKBOT         .dw R_STKBOT            ; Address of the Calculator stack in memory.
                                       ; This is where Basic does the math calculations
STKEND         .dw R_STKBOT            ; End of the Calculator stack
BERG           .db 0                   ; Calculator's b register
MEM            .dw MEMBOT              ; Address of area used for calculator's memory.
                                       ; (Usually MEMBOT, but not always.)
               .db 0                   ; Not Used
DF_SZ          .db 2                   ; The number of lines (including one blank line)
                                       ; in the lower part of the screen.
S_TOP          .dw 1                   ; The number of the top program line in automatic listings
LAST_K         .db 0ffh,0ffh           ; Shows which keys pressed
               .db 0ffh                ; Debounce status of the keyboard
MARGIN         .db 55                  ; Number of blank lines above or below picture:
                                       ; 55 in Britain, 31 in America

; Make NXTLIN equal Line_10 if you want the code to autorun,
; or make it equal R_DFILE if you do not want it to autorun

NXTLIN         .dw Line_10             ; Address of next program line to be executed

OLDPPC         .dw 0                   ; Line number of which CONT jumps
FLAGX          .db 0                   ; Various flags
STRLEN         .dw 0                   ; Length of string type destination in assignment
T_ADDR         .dw 0c8dh               ; Address of next item in syntax table (very unlikely to be useful)
SEED           .dw 0                   ; The seed for RND. This is the variable that is set by RAND
FRAMES         .dw 0ffffh              ; Counts the frames displayed on the television.
                                       ; Bit 15 is 1. Bits 0 to 14 are decremented for each frame
                                       ; set to the television. This can be used for timing, but
                                       ; PAUSE also uses it. PAUSE resets to 0 bit 15, & puts in
                                       ; bits 0 to 14 the length of the pause. When these have been
                                       ; counted down to zero, the pause stops. If the pause stops 
                                       ; because of a key depression, bit 15 is set to 1 again.
COORDS         .db 0                   ; x-coordinate of last point PLOTted
               .db 0                   ; y-coordinate of last point PLOTted
PR_CC          .db 0bch                ; Less significant byte of address of next position for
                                       ; LPRINT to print as (in PRBUFF)
S_POSN         .db 33                  ; Column number for PRINT position
               .db 24                  ; Line number for PRINT position
CDFLAG         .db 01000000b           ; Various flags. Bit 7 is on (1) during compute & display mode
PRBUFF         

Line_10:
               .db 0,0                ; line number
               .dw REM1 - $ - 2	       ; line length
               .db 0f9h                ; RAND
               .db 0d4h                ; USR
	       .db 0c5h                ; VAL
	       .db 00bh                ; "
	       ;16444+20 [START1]
               .db _1,_6,_4,_6,_4
	       .db 00bh                ; "
               .db 076h                ; NEWLINE
; First REM (hidden)
; 44bytes free.
REM1
               .db 0,0                 ; line number
               .dw Line_0 - $ - 2      ; line length
               .db 0eah                ; REM
MEMBOT
START1:
	call $a2a
	ld hl,R_DFILE+1
	ld C, $15
	ld A,0
LOOP0	ld B, $21
LOOP1
	cp (HL)
	jr nz,LOOP2
	ld (HL),$80
LOOP2	
	inc HL
	djnz LOOP1
	dec C
	jr nz,LOOP0

	ld BC,$090B ; X=11 Y=9 
	call $8f5 
	ld BC,ENDTEXT-TEXT1 
	ld DE,TEXT1  
	call $b6b
        ret
END1:	

	.fill 44-($-MEMBOT),0
               .db 076h                ; NEWLINE
Line_0
               .db 0,0                 ; line number
               .dw R_DFILE - $ - 2     ; line length
               .db 0eah                ; REM

; *********************************
; Put your code here. Do not use
; the Z80 HALT instruction as the
; ZX81 will see it as a NEWLINE
; and it could cause your program
; crash (maybe).
; *********************************
START2:
TEXT1:
	.db H,E,L,L,O,_,W,O,R,L,D
ENDTEXT:

END2
; *********************************
; Do not change anything after this
; *********************************

               .db 076h                ; NEWLINE


R_DFILE        .fill 25,076h           ; Compacted D_FILE (25 NEWLINE's)
R_VARS
               .db 080h                ; End of Variables Marker
R_E_LINE
R_STKBOT
R_LAST
               .end

A	.equ $26
B	.equ $27
C	.equ $28
D	.equ $29
E	.equ $2A
F	.equ $2B
G	.equ $2C
H	.equ $2D
I	.equ $2E
J	.equ $2F
K	.equ $30
L	.equ $31
M	.equ $32
N	.equ $33
O	.equ $34
P	.equ $35
Q	.equ $36
R	.equ $37
S	.equ $38
T	.equ $39
U	.equ $3A
V	.equ $3B
W	.equ $3C
X	.equ $3D
Y	.equ $3E
Z	.equ $3F
_	.equ $00
_0	.equ $1C
_1	.equ $1D
_2	.equ $1E
_3	.equ $1F
_4	.equ $20
_5	.equ $21
_6	.equ $22
_7	.equ $23
_8	.equ $24
_9	.equ $25
AUTOBOOT_2.P
(159 Bytes) Downloaded 331 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX81CRSS.ASM

Post by XavSnap »

Code: Select all

;******************************************
; Do not change anything after this
;******************************************
:?
Done...
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply