ZX81CRSS.ASM

Discussion about ZX80 / ZX81 Software
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81CRSS.ASM

Post by dr beep »

When you want the shortest start to MC you can use this.
Even the repair of Dfile can be done on the screen when you clear the screen and the code too,
but that is a bit harder.

Code: Select all

; Shortest code to autostart MC on a ZX81

	org #4009

; in LOWRES more sysvar are used, but in this way the shortest code
; over sysvar to start machinecode. This saves 11 bytes of BASIC

basic   ld h,dfile/256			; highbyte of dfile
        jr init1

	db 236				; BASIC over DFILE data
	db 212,28			; The RAND USR N will start MC at "basic"
	db 126,143,0,18

eline	dw last
chadd	dw last-1
        db 0,0,0,0,0,0			; x
berg	db 0				; x

mem	db 0,0				; x OVERWRITTEN ON LOAD

init1	ld l, dfile mod 256		; low byte of dfile
	jr init2			
		
lastk	db 255,255,255
margin  db 55

nxtlin  dw basic			; BASIC-line over sysvar	

	db 0,0
flagx	db 0

	db 0,0,0			; x
	db 0,0,0			; x

frames  dw 65535

init2	jp init4			; start your program
	db 0,0

cdflag  db 64

; THESE 3 BYTES ARE THE ONLY NOT USEABLE BYTES (but can be set on screen too)
start	ld (basic+3),hl			; repair lowres display

; HERE COMES YOUR PROGRAM
prog	jr prog				; start game, make screen over keytab

; The screen
dfile 	block 25,118


vars    db 128
last	equ $   	

end                	
nollkolltroll
Posts: 325
Joined: Sat Sep 27, 2014 8:02 pm
Location: Stockholm, Sweden

Re: ZX81CRSS.ASM

Post by nollkolltroll »

Very nice way to save some bytes in 1k-mode, which is truly needed.
/Adam
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81CRSS.ASM

Post by dr beep »

nollkolltroll wrote: Sat Jan 12, 2019 9:05 am Very nice way to save some bytes in 1k-mode, which is truly needed.
In fact,when not returning to BASIC you could set a table or variables on some part of the sysvar.
Take a look at the source of RUB-1K where data is copied over sysvar and then that part of memory is used to set up
the sides of the cube. Reuse of 21 bytes. In 1K hires you can reuse dfile to lastk too.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX81CRSS.ASM

Post by dr beep »

XavSnap wrote: Fri Mar 16, 2018 11:19 pm 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
I mentioned it before.... my model places the call to machine code fully over the sysvar.

Here is an example.

https://sinclairzxworld.com/download/file.php?id=9398

and even more.... there is also no line with the REM. The machine never goes to the editor and therefore not needed.

Besides that... also routine ps and data are copied over sysvar again. A random number routine here.
Post Reply