"Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by XavSnap »

This code don't work?

(ASM2)

Code: Select all

@CURSEUR=8F5
@CLEAR=A2A
@CHAINE=B6B

CALL CLEAR ; CLS
LD BC,0707  
CALL CURSEUR ; AT 7,7
LD BC,000A 
LD DE,TEXT1  
CALL CHAINE ; PRINT CHAIN LEN=BC;@TEXT1
@TEXT1
DEFM "HELLO WORLD"

Xavier ...on the Facebook groupe : "Zx81 France"(fr)
daybyter
Posts: 17
Joined: Wed Nov 23, 2016 11:03 pm

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by daybyter »

olofsen wrote:Does the attached slightly modified version work, with just RUN and normal sz81 settings?
Works! Thanks a lot!

Now I have to figure out, why your version works.
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by XavSnap »

Probably because the CHAINE(B6B) rom jump get the A, DE and BE registers, and print only the A.
But, you had to tag each strings with the string length!

DEFM 11,"HELLO WORLD"
...
And get the length using:
LD A,(HL)
LD C,A

To print a variable length string to the screen:

Code: Select all


@CURSEUR=8F5
 

	LD BC,0808 ; PRINT AT VALUE
	LD HL,TEXT1 ; TEXT OFFSET
	CALL GDISP; Go to Display proc. VVVV
	RET ; EXIT TO BASIC.
;------------------------------
@GDISP
        PUSH HL ; SAVE ACTUAL VALUE (TEXT1 offset)
	CALL CURSEUR ; AT 8,8; move cursor to...(HL changed!!!)
	POP HL ; RELOAD VALUE (TEXT1 offset)
	DEC HL
@SPRINT
	INC HL
	LD A,(HL)
	CP FF
	RET Z ; IF AF flag is 1 'Equal' ;;;; EXIT THE CALL PROC. AAAA
	RST 10 ; PUT A TO THE SCREEN (and jump to next line)
	JR SPRINT ; NOT A CALL COMMAND !!! 1 CALL= 1 RET
@TEXT1
	DEFM "HELLO WORLD"
	DEFB FF
	
Have a look to : http://zx81.vb81.free.fr/ASM2.html
(Mnemonics table!)
Or
The red book: "La pratique du ZX81 tome 2" in french! :oops:
http://zx81.ordi5.free.fr/others/
Last edited by XavSnap on Thu Feb 16, 2017 11:40 pm, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by XavSnap »

Code: Select all

@CURSEUR=8F5
   LD BC,0808 
   LD HL,TEXT1
   CALL GDISP
   RET 
@GDISP
   PUSH HL
   CALL CURSEUR
   POP HL
   DEC HL
@SPRINT
   INC HL
   LD A,(HL)
   CP FF
   RET Z 
   RST 10 
   JR SPRINT
@TEXT1
   DEFB "HELLO WORLD"
   DEFB FF
   
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by olofsen »

Thinking a bit deeper about the Mastering Machine Code example, my confusion started with : ;)

Code: Select all

20 REM ** TYPE RUN **
And while the following lines are actually equivalent, at first glance the first form seemed wrong, and the reason the example didn't run (the VAL saves a few bytes):

Code: Select all

10 RAND VAL "USR 16514"
10 RAND USR VAL "16514"
Finally, the machine code did not start at 16514, but as noted at 16526.

The interesting thing about the MMC example is that the first line of SPRINT, the POP, gets the address of the string to be printed, because the address of the next instruction or data after the CALL SPRINT is on the stack. The PUSH accomplishes that the RET returns to the first instruction after the string data. Note that CALL PRINT_CHAR can be replaced by RST 10H.

Code: Select all

SPRINT  POP HL
        LD A,(HL)
        INC HL
        PUSH HL
        CP $FF
        RET Z       
        RST 10H
        JR SPRINT
An updated version is attached.
Attachments
helloworld.zip
(2.92 KiB) Downloaded 140 times
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: "Hello World" for pasmo & ZX Assembler 2 using MMCoYZX81

Post by XavSnap »

Code: Select all

;------- TASM ASM mnemonics. -------
; Compile this file using:
; Set TASMOPTS = -b
; tasm -80 ThisCode.tas MyBinary.BIN
;-----------------------------------
; Zx81 Program name: VB81 XuR [helloworld.p] :
; REM   line   name: D=16514/16543 : H=4082/409F

#define ORG  .org       ; TASM cross-assembler definitions
#define equ  .equ
;-----------------------------------
;- ZX81 CARACTERS CODES ------------
;-----------------------------------
_   .equ $00
D   .equ $29
E   .equ $2A
H   .equ $2D
L   .equ $31
O   .equ $34
R   .equ $37
W   .equ $3C
;-----------------------------------

;------------------------------------
;-Basic sub-routine entry.          -
;+----------------------------------+
; Lb4082  ;  <- USR Basic Enty.
;+----------------------------------+


ORG $4082 ; [@16514/@h4082]
Lb4082: ; <- USR Basic Enty.
	CALL Lb4096 ; [16534]
.db H,E,L,L,O,$FF,$CD,$96; ZX-TEXT
.db $40,_,W,O,R,L,D,$FF; ZX-TEXT
	RET ; ==========================

Lb4096:
	POP HL 
	LD A,(HL) 
	INC HL 
	PUSH HL 
	CP $FF ; [255]
	RET Z 
	RST 10H ; Display= A reg.
	JR Lb4096 ; [$4096:16534]
.end
As already noticed, the "CALL" function is a "GOSUB" to a sub-routine.
Using:
CALL Lb4096 ; [16534]
LBnext: ; continue!
RET
...
Lb4096:
RET ; return to LBnext:

In your exemple, the "HELLO-WORLD" is read like MC opcodes! (ooops!)
Just ADD a RET (return to basic) after the CALL!
The RET ( RET ; ==========================) may be move...
Never place the CPU pointer (PC) to DB datas, Stop it before!
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply