Page 1 of 1

Lesson H2 - Hello World on the ZX Spectrum

Posted: Sun Sep 01, 2019 9:35 pm
by akuyou


http://www.chibiakumas.com/z80/helloworld.php#LessonH2

The ZX Spectrum is one of the most popular Z80 machines around, and it's well emulated too!

Unfortunately, making usable Disk or Tape images can be a bit tricky, but we can get around it with some work!

Re: Lesson H2 - Hello World on the ZX Spectrum

Posted: Thu Dec 07, 2023 8:06 pm
by _dw
For comparison

Forth (hello.fth)

Code: Select all

." Hello Word!"
M4 FORTH (use ../fth2m4.sh hello.fth > hello.m4)

Code: Select all

include(`../M4/FIRST.M4')dnl
  ifdef __ORG
    org __ORG
  else
    org 32768
  endif
  INIT(60000)
PRINT({"Hello World!"})
  STOP
ZX Spectrum asm (use ../compile.sh hello 32768)

Code: Select all

  ifdef __ORG
    org __ORG
  else
    org 32768
  endif
  

  

;   ===  b e g i n  ===
    ld  [Stop+1], SP    ; 4:20      init   storing the original SP value when the "bye" word is used
    ld    L, 0x1A       ; 2:7       init   Upper screen
    call 0x1605         ; 3:17      init   Open channel
    ld   HL, 0xEA60     ; 3:10      init   Return address stack = 60000
    exx                 ; 1:4       init
    push DE             ; 1:11      print     "Hello World!"
    ld   BC, size101    ; 3:10      print     Length of string101
    ld   DE, string101  ; 3:10      print     Address of string101
    call 0x203C         ; 3:17      print     Print our string with ZX 48K ROM
    pop  DE             ; 1:10      print
Stop:                   ;           stop
    ld   SP, 0x0000     ; 3:10      stop   restoring the original SP value when the "bye" word is used
    ld   HL, 0x2758     ; 3:10      stop
    exx                 ; 1:4       stop
    ret                 ; 1:10      stop
;   =====  e n d  =====

STRING_SECTION:
string101:
    db "Hello World!"
size101              EQU $ - string101
A hello.tap containing both the binary program and the basic loader (with the program duration calculated for testing) will also be created automatically. The tap file is immediately launched in fuse after compilation.