(*
This file shows examples of the emulation additions made to Zeus-ish up to version v2.64

For the purposes of this example I'm going to assume this source is located
in a folder called c:\zeustest

It is also important you use the syntax highlighting editor. Please select this using
the Config tab.

Having loaded this file click on the "Assemble" button below to assemble it.

Now, press function key F7 - this will execute a single instruction.
Pressing F8 executes at full speed (but doesn't update the editor) - move to the "Emulator"
tab to watch the code running.
Pressing F9 stops the emulator.

The emulator has two distinct modes. If you start it from the editor, by pressing F7 or F8
in the editor then if the mouse pointer is hovered over a register it will show the value
of that register.

If the emulator is started using F7/F8 while on the emulator tab, or using the buttons on the
emulator tab then it runs without updating the editor. This avoids irritating flicker while
editing.

Note that the highlighted run line and emulator messages may well be wrong if the source has
being edited since it was last assembled. When starting emulation remember to assemble the source
first...

You can insert breakpoints by clicking in the editor margin (on a blue dot). If the
emulator was started from the editor (F7/F8) then it will stop and move to the relevent
line in the event of hitting a breakpoint. If started from the emulator tab it does not,
this allows you to inspect the registers and screen without jumping back to the source.

At this point the editor's integration with the emulator is far from complete. I'm not
guaranteeing it ever will be complete either - this is all done for amusement and it's
not all that amusing at the moment ;)
*)

; Example source

; Print control codes

cDel                    equ $08                         ;
cCret                   equ $0D                         ;
cCls                    equ $0C                         ;
cClr                    equ $1B                         ;
cHome                   equ $0E                         ;

; Print colour select characters

cBlack                  equ $00                         ;
cBlue                   equ $01                         ;
cRed                    equ $02                         ;
cMagenta                equ $03                         ;
cGreen                  equ $04                         ;
cCyan                   equ $05                         ;
cYellow                 equ $06                         ;
cWhite                  equ $07                         ;

; This exports a file for external emulation.
; It also tells Zeus where to start internal emulation - the parameters are the file to generate
; where to start the stack-pointer (Stack) and where to start executing code (Start)

                        output_szx "c:\zeustest\test_264.szx",Stack,Start       ; Generate code to test

                        org $8000                       ; Somewhere safe

Start                   di                              ; Make sure we're not interrupted
                        ld sp,Stack                     ; Set the stack to the top of memory

                        ld a,cCls                       ; Clear the screen
                        call Print                      ;

Loop                    ld hl,(Value)                   ; Load a value
                        inc hl                          ;
                        ld (Value),hl                   ;

                        ld a,cRed                       ; Show the first in red - WAS blue
                        call Print                      ;

                        call PrintHex_HL                ; Show the value

                        call Print_Sp                   ; " "

;                        call PrintStrFollow             ; Print the string following this call
;                        noflow                          ; Turn the warning off
;                        db cCyan," Hello there!"
;                        db cCret,"exciting, isn't it...",cCret,0

                        ; We're done...

                        jp Loop                         ; Stop all the excitement

; Print the zero-terminated string pointed to by HL

PrintStr                proc                            ;

                        push hl,af                      ;

Loop                    ld a,(hl)                       ;
                        inc hl                          ;
                        or a                            ;
                        jr z,Exit                       ;

                        call Print                      ;
                        jr Loop                         ;

Exit                    pop af,hl                       ;
                        retp                            ; (RET)

; Print the string following the call in memory

PrintStrFollow          proc                            ;

                        ex (sp),hl                      ;
                        push af                         ;

Loop                    ld a,(hl)                       ;
                        inc hl                          ;
                        or a                            ;
                        jr z,Exit                       ;

                        call Print                      ;

                        jr Loop                         ;

Exit                    pop af                          ;
                        ex (sp),hl                      ;

                        retp                            ; (RET)

; Print the contents of HL in hex

PrintHex_HL             ld a,h                          ;
                        call PrintHex_A                 ;

                        ld a,l                          ;

                        ; Print the contents of A in hex

PrintHex_A              call PH2                        ;

PH2                     rrca                            ;
                        rrca                            ;
                        rrca                            ;
                        rrca                            ;

                        push af                         ;

                        and $0F                         ;

                        add a,"0"                       ;
                        cp "9"+1                        ;
                        jr c,PH3                        ;

                        add a,"A"-("9"+1)               ;

PH3                     call Print                      ;

                        pop af                          ;
                        ret                             ;

; Print a space

Print_Sp                push af                         ; Save

                        ld a,' '                        ; Print a space
                        call Print                      ;

                        pop af                          ; Done
                        ret                             ;

; A print character routine. Proportionally spaced characters

Print                   push ix,hl,de,bc,af             ; Save them

                        cp cWhite+1                     ;
                        jr c,PrintColour                ;

                        cp cCls                         ;
                        jr z,PrintCls                   ;

                        cp cCret                        ;
                        jr z,PrintCret                  ;

                        cp cHome                        ;
                        jr z,PrintHome                  ;

                        ld h,PrintWidths/256            ;
                        ld l,a                          ;

                        ld a,(pCurX)                    ;
                        add a,(hl)                      ;
                        call c,PrintDoCret              ;

                        call PrintOutChar               ;

                        ld a,(pCurX)                    ;
                        add a,(hl)                      ;
                        ld (pCurX),a                    ;

PrintExit               pop af,bc,de,hl,ix              ;
                        ret                             ;

; Set a colour

PrintColour             cp 4                            ; Above green don't make them bright
                        jr nc,PrintCol1                 ;

                        or $40                          ; Bright

PrintCol1               ld (CurCol),a                   ;
                        jr PrintExit                    ;

; Carriage return

PrintCret               call PrintDoCret                ;
                        jr PrintExit                    ;

; Clear screen - this clears it slowly with a fade effect

PrintCls                ld e,$00                        ;
                        ld hl,$5800                     ; Hint: Hover the mouse over the "hl" while stepping this with F7
                        ld bc,$02FF                     ;

pC1                     ld a,(hl)                       ;
                        and $07                         ;
                        jr z,pC2                        ;

                        set 0,e                         ;
                        dec (hl)                        ;
pC2                     cpi                             ;
                        jp pe,pC1                       ;

                        call Delay                      ;

                        bit 0,e                         ;
                        jr nz,PrintCls                  ;

                        ld hl,$4000                     ;
                        ld de,$4001                     ;
                        ld bc,$1800                     ;

                        xor a                           ;
                        ld (hl),a                       ;

                        ldir                            ;

                        ld a,(CurCol)                   ;
                        ld (hl),a                       ;

                        ld bc,$02FF                     ;

                        ldir                            ;

                        xor a                           ;
                        out ($FE),a                     ;

PrintHome               xor a                           ;
                        ld (pCurX),a                    ;
                        ld (ppCurY),a                   ;

                        ld a,cWhite                     ;
                        ld (CurCol),a                   ;

                        ld hl,$4000                     ;
                        ld (pCurY),hl                   ;

                        jr PrintExit                    ;

; A suitable delay for the fade

Delay                   push bc                         ;
                        ld bc,1000                      ;
Del1                    cpi                             ;
                        dec hl                          ;
                        jp pe,Del1                      ;
                        pop bc                          ;
                        ret                             ;

; Do the carriage return

PrintDoCret             ld a,(ppCurY)                   ;
                        inc a                           ;
                        cp 24                           ; Hit bottom?
                        jr c PrintSetUpY                ; No, skip

                        ld a,0                          ; LHS
                        ld (pCurX),a                    ;

                        ; Scroll the screen up

                        push hl                         ; We need to save L

                        ; (I'm tired, there has to be a better way than this...)

                        ld c,0                          ; Scroll a line

ScrollLoop              ld b,c                          ;
                        inc b                           ;
                        call CopyLine_B_To_C            ;

                        inc c                           ;
                        ld a,c                          ;
                        cp 23                           ;
                        jr nz ScrollLoop                ;

                        ld c,23                         ;
                        call ClearLine_C                ;

                        pop hl                          ;
                        ret                             ; Done

PrintSetUpY             ld (ppCurY),a                   ;

                        and $1F                         ;

                        push hl                         ;

                        ld l,a                          ;
                        ld h,$00                        ;

                        add hl,hl                       ;

                        ld de,YTable                    ;
                        add hl,de                       ;

                        ld a,(hl)                       ;
                        inc hl                          ;
                        ld h,(hl)                       ;
                        ld l,a                          ;

                        ld (pCurY),hl                   ;

                        xor a                           ;
                        ld (pCurX),a                    ;

                        pop hl                          ;
                        ret                             ;

; Output the character

PrintOutChar            bit 7,l                         ; characters $00..$7F only
                        ret nz                          ;

                        push hl                         ;

                        ld h,0                          ;

                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;

                        ld de,PrintChars-256            ;
                        add hl,de                       ;

                        push hl                         ;
                        pop ix                          ;

                        ld a,(pCurX)                    ;

                        rrca                            ;
                        rrca                            ;
                        rrca                            ;
                        and $1F                         ;

                        ld de,(pCurY)                   ;

                        or e                            ;
                        ld e,a                          ;

                        push de                         ;

                        ld a,d                          ;
                        rrca                            ;
                        rrca                            ;
                        rrca                            ;
                        and $03                         ;
                        or $58                          ;
                        ld d,a                          ;

                        ld a,(CurCol)                   ;
                        ld (de),a                       ;
                        inc de                          ;
                        ld (de),a                       ;

                        pop de                          ;

                        ld a,(pCurX)                    ;
                        and $07                         ;
                        ld c,a                          ;

                        ld b,$08                        ;

OutCharL                ld h,(ix)                       ;
                        ld l,$00                        ;

                        ld a,c                          ;
                        or a                            ;
                        jr z,OCL1                       ;

OCL2                    srl h                           ;
                        rr l                            ;
                        dec a                           ;
                        jr nz,OCL2                      ;

OCL1                    ld a,(de)                       ;
                        xor h                           ;
                        ld (de),a                       ;

                        inc e                           ;

                        ld a,(de)                       ;
                        xor l                           ;
                        ld (de),a                       ;

                        dec e                           ;

                        inc ix                          ;
                        inc d                           ;

                        djnz OutCharL                   ;

                        pop hl                          ;
                        ret                             ;

; Copy line [B] to [C]

CopyLine_B_To_C         proc                            ;
                        push bc                         ; Save

                        ; Point at the src line

                        ld a,b                          ;
                        add a,a                         ;
                        add a,low YTable                ;
                        ld l,a                          ;

                        ld h,high YTable                ;

                        ld e,(hl)                       ;
                        inc l                           ;
                        ld d,(hl)                       ;

                        push de                         ; Save it

                        ; Point at the dst line

                        ld a,c                          ;
                        add a,a                         ;
                        add a,low YTable                ;
                        ld l,a                          ;

                        ld h,high YTable                ;

                        ld e,(hl)                       ;
                        inc l                           ;
                        ld d,(hl)                       ;

                        pop hl                          ;

                        ; Copy it

CL_Lp                   push hl                         ; Save
                        push de                         ;

                        ld bc,$20                       ; Copy the line
                        ldir                            ;

                        pop de                          ;
                        pop hl                          ;

                        inc d                           ;
                        inc h                           ;

                        ld a,h                          ;
                        and $07                         ;
                        jr nz CL_Lp                     ;

                        ; Now, copy the attributes

                        pop bc                          ; Restore
                        push bc                         ;

                        ld l,c                          ; Dest
                        ld h,0                          ;

                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;

                        ld de,$5800                     ; Attribute base
                        add hl,de                       ;
                        ex de,hl                        ;
                        ld hl,$20                       ;
                        add hl,de                       ;
                        ld bc,$20                       ;
                        ldir                            ;

                        pop bc                          ;
                        retp                            ; Done

; Clear a line

ClearLine_C             proc                            ;
                        push bc                         ; Save

                        ; Point at the src line

                        ld a,c                          ;
                        add a,a                         ;
                        add a,low YTable                ;
                        ld l,a                          ;

                        ld h,high YTable                ;

                        ld a,(hl)                       ;
                        inc l                           ;
                        ld h,(hl)                       ;
                        ld l,a                          ;

                        ; Clear it

CL_Lp                   push hl                         ; Save

                        ld b,4                          ; Clear the line
                        ld a,0                          ;

CL_Lp2                  loop 8                          ;
                          ld (hl),a                     ;
                          inc l                         ;
                          lend                          ;
                        djnz CL_Lp2                     ;

                        pop hl                          ; Restore

                        inc h                           ;

                        ld a,h                          ;
                        and $07                         ;
                        jr nz CL_Lp                     ;

                        ; Now, clear the attributes

                        ld l,c                          ; Dest
                        ld h,0                          ;

                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;
                        add hl,hl                       ;

                        ld de,$5800                     ; Attribute base
                        add hl,de                       ;

                        ld b,4                          ; Clear the line
                        ld a,0                          ;

CL_Lp3                  loop 8                          ;
                          ld (hl),a                     ;
                          inc l                         ;
                          lend                          ;
                        djnz CL_Lp3                     ;

                        pop bc                          ;
                        retp                            ; Done


; Screen addresses for the character rows

                        align 64

YTable                  defw $4000,$4020,$4040,$4060    ;
                        defw $4080,$40A0,$40C0,$40E0    ;
                        defw $4800,$4820,$4840,$4860    ;
                        defw $4880,$48A0,$48C0,$48E0    ;
                        defw $5000,$5020,$5040,$5060    ;
                        defw $5080,$50A0,$50C0,$50E0    ;
                        defw 0,0,0,0,0,0,0,0            ; So running off the end isn't fatal

; Character set graphics

                        align 256                       ; Put these on page boundaries

PrintChars              dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........

                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........
                        dg X.......
                        dg ........

                        dg X.X.....
                        dg X.X.....
                        dg X.X.....
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........

                        dg .X.X....
                        dg .X.X....
                        dg XXXXX...
                        dg .X.X....
                        dg XXXXX...
                        dg .X.X....
                        dg .X.X....
                        dg ........

                        dg ..X.....
                        dg .XXXX...
                        dg X.X.....
                        dg .XXX....
                        dg ..X.X...
                        dg XXXX....
                        dg ..X.....
                        dg ........

                        dg XX......
                        dg XX..X...
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg X..XX...
                        dg ...XX...
                        dg ........

                        dg .X......
                        dg X.X.....
                        dg X.X.....
                        dg .X......
                        dg X.X.X...
                        dg X..X....
                        dg .XX.X...
                        dg ........

                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........

                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg .X......
                        dg ..X.....
                        dg ........

                        dg X.......
                        dg .X......
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg ........

                        dg ..X.....
                        dg X.X.X...
                        dg .XXX....
                        dg ..X.....
                        dg .XXX....
                        dg X.X.X...
                        dg ..X.....
                        dg ........

                        dg ........
                        dg ..X.....
                        dg ..X.....
                        dg XXXXX...
                        dg ..X.....
                        dg ..X.....
                        dg ........
                        dg ........

                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg .X......
                        dg .X......
                        dg X.......
                        dg ........

                        dg ........
                        dg ........
                        dg ........
                        dg XXXXX...
                        dg ........
                        dg ........
                        dg ........
                        dg ........

                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg X.......
                        dg ........

                        dg ........
                        dg ....X...
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg ........
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X..XX...
                        dg X.X.X...
                        dg XX..X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg ..X.....
                        dg .XX.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg .XXX....
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg ....X...
                        dg ..XX....
                        dg .X......
                        dg X.......
                        dg XXXXX...
                        dg ........

                        dg XXXXX...
                        dg ....X...
                        dg ...X....
                        dg ..XX....
                        dg ....X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg ...X....
                        dg ..XX....
                        dg .X.X....
                        dg X..X....
                        dg XXXXX...
                        dg ...X....
                        dg ...X....
                        dg ........

                        dg XXXXX...
                        dg X.......
                        dg XXXX....
                        dg ....X...
                        dg ....X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg ..XXX...
                        dg .X......
                        dg X.......
                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg XXXXX...
                        dg ....X...
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg .X......
                        dg .X......
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg .XXXX...
                        dg ....X...
                        dg ...X....
                        dg XXX.....
                        dg ........

                        dg ........
                        dg ........
                        dg X.......
                        dg ........
                        dg X.......
                        dg ........
                        dg ........
                        dg ........

                        dg ........
                        dg ........
                        dg .X......
                        dg ........
                        dg .X......
                        dg .X......
                        dg X.......
                        dg ........

                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg .X......
                        dg ..X.....
                        dg ...X....
                        dg ........

                        dg ........
                        dg ........
                        dg XXXXX...
                        dg ........
                        dg XXXXX...
                        dg ........
                        dg ........
                        dg ........

                        dg X.......
                        dg .X......
                        dg ..X.....
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg ...X....
                        dg ..X.....
                        dg ..X.....
                        dg ........
                        dg ..X.....
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X.X.X...
                        dg X.XXX...
                        dg X.XX....
                        dg X.......
                        dg .XXXX...
                        dg ........

                        dg ..X.....
                        dg .X.X....
                        dg X...X...
                        dg X...X...
                        dg XXXXX...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg ........

                        dg XXXXX...
                        dg X.......
                        dg X.......
                        dg XXXX....
                        dg X.......
                        dg X.......
                        dg XXXXX...
                        dg ........

                        dg XXXXX...
                        dg X.......
                        dg X.......
                        dg XXXX....
                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........

                        dg .XXXX...
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X..XX...
                        dg X...X...
                        dg .XXXX...
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg XXXXX...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg XXX.....
                        dg .X......
                        dg .X......
                        dg .X......
                        dg .X......
                        dg .X......
                        dg XXX.....
                        dg ........

                        dg ....X...
                        dg ....X...
                        dg ....X...
                        dg ....X...
                        dg ....X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg X...X...
                        dg X..X....
                        dg X.X.....
                        dg XX......
                        dg X.X.....
                        dg X..X....
                        dg X...X...
                        dg ........

                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg XXXXX...
                        dg ........

                        dg X...X...
                        dg XX.XX...
                        dg X.X.X...
                        dg X.X.X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg XX..X...
                        dg X.X.X...
                        dg X..XX...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X.X.X...
                        dg X..X....
                        dg .XX.X...
                        dg ........

                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg X.X.....
                        dg X..X....
                        dg X...X...
                        dg ........

                        dg .XXX....
                        dg X...X...
                        dg X.......
                        dg .XXX....
                        dg ....X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg XXXXX...
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg .X.X....
                        dg ..X.....
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X.X.X...
                        dg X.X.X...
                        dg XX.XX...
                        dg X...X...
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg .X.X....
                        dg ..X.....
                        dg .X.X....
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg X...X...
                        dg X...X...
                        dg .X.X....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ........

                        dg XXXXX...
                        dg ....X...
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg X.......
                        dg XXXXX...
                        dg ........

                        dg XXXXX...
                        dg XX......
                        dg XX......
                        dg XX......
                        dg XX......
                        dg XX......
                        dg XXXXX...
                        dg ........

                        dg ........
                        dg X.......
                        dg .X......
                        dg ..X.....
                        dg ...X....
                        dg ....X...
                        dg ........
                        dg ........

                        dg XXXXX...
                        dg ...XX...
                        dg ...XX...
                        dg ...XX...
                        dg ...XX...
                        dg ...XX...
                        dg XXXXX...
                        dg ........

                        dg ..X.....
                        dg .XXX....
                        dg X.X.X...
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ........
                        dg ........

                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg XXXXX...
                        dg ........

                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........
                        dg ........

                        dg ........
                        dg ........
                        dg .XX.X...
                        dg X..XX...
                        dg X...X...
                        dg X..XX...
                        dg .XX.X...
                        dg ........

                        dg X.......
                        dg X.......
                        dg X.XX....
                        dg XX..X...
                        dg X...X...
                        dg XX..X...
                        dg X.XX....
                        dg ........

                        dg ........
                        dg ........
                        dg .XXXX...
                        dg X.......
                        dg X.......
                        dg X.......
                        dg .XXXX...
                        dg ........

                        dg ....X...
                        dg ....X...
                        dg .XX.X...
                        dg X..XX...
                        dg X...X...
                        dg X..XX...
                        dg .XX.X...
                        dg ........

                        dg ........
                        dg ........
                        dg .XXX....
                        dg X...X...
                        dg XXXXX...
                        dg X.......
                        dg .XXX....
                        dg ........

                        dg ..X.....
                        dg .X......
                        dg .X......
                        dg XXX.....
                        dg .X......
                        dg .X......
                        dg .X......
                        dg ........

                        dg ........
                        dg ........
                        dg .XXXX...
                        dg X...X...
                        dg X..XX...
                        dg .XX.X...
                        dg ....X...
                        dg .XXX....

                        dg X.......
                        dg X.......
                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg X.......
                        dg ........
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........

                        dg ........
                        dg ..X.....
                        dg ........
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg XX......

                        dg X.......
                        dg X.......
                        dg X..X....
                        dg X.X.....
                        dg XXX.....
                        dg X..X....
                        dg X...X...
                        dg ........

                        dg XX......
                        dg .X......
                        dg .X......
                        dg .X......
                        dg .X......
                        dg .X......
                        dg XXX.....
                        dg ........

                        dg ........
                        dg ........
                        dg XX.X....
                        dg X.X.X...
                        dg X.X.X...
                        dg X.X.X...
                        dg X.X.X...
                        dg ........

                        dg ........
                        dg ........
                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg ........

                        dg ........
                        dg ........
                        dg .XXX....
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg .XXX....
                        dg ........

                        dg ........
                        dg ........
                        dg XXXX....
                        dg X...X...
                        dg X...X...
                        dg XXXX....
                        dg X.......
                        dg X.......

                        dg ........
                        dg ........
                        dg .XXXX...
                        dg X...X...
                        dg X...X...
                        dg .XXXX...
                        dg ....X...
                        dg ....X...

                        dg ........
                        dg ........
                        dg X.XX....
                        dg XX......
                        dg X.......
                        dg X.......
                        dg X.......
                        dg ........

                        dg ........
                        dg ........
                        dg .XXXX...
                        dg X.......
                        dg .XXX....
                        dg ....X...
                        dg XXXX....
                        dg ........

                        dg ........
                        dg ..X.....
                        dg XXXXX...
                        dg ..X.....
                        dg ..X.....
                        dg ..X.....
                        dg ..x.....                     ; This used to be ...XX...
                        dg ........

                        dg ........
                        dg ........
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg .XXXX...
                        dg ........

                        dg ........
                        dg ........
                        dg X...X...
                        dg X...X...
                        dg .X.X....
                        dg .X.X....
                        dg ..X.....
                        dg ........

                        dg ........
                        dg ........
                        dg X...X...
                        dg X...X...
                        dg X...X...
                        dg X.X.X...
                        dg .X.X....
                        dg ........

                        dg ........
                        dg ........
                        dg X...X...
                        dg .X.X....
                        dg ..X.....
                        dg .X.X....
                        dg X...X...
                        dg ........

                        dg ........
                        dg ........
                        dg X..X....
                        dg X..X....
                        dg X..X....
                        dg XXXX....
                        dg ...X....
                        dg XXX.....

                        dg ........
                        dg ........
                        dg XXXXX...
                        dg ...X....
                        dg ..X.....
                        dg .X......
                        dg XXXXX...
                        dg ........

                        dg ..XX....
                        dg .X......
                        dg .X......
                        dg X.......
                        dg .X......
                        dg .X......
                        dg ..XX....
                        dg ........

                        dg ........
                        dg X.......
                        dg X.......
                        dg ........
                        dg ........
                        dg X.......
                        dg X.......
                        dg ........

                        dg XX......
                        dg ..X.....
                        dg ..X.....
                        dg ...X....
                        dg ..X.....
                        dg ..X.....
                        dg XX......
                        dg ........

                        dg .X.X....
                        dg ........
                        dg .XXX....
                        dg X...X...
                        dg XXXXX...
                        dg X.......
                        dg .XXX....
                        dg ........

                        dg ........
                        dg ........
                        dg ....X...
                        dg .XXX....
                        dg X.......
                        dg ........
                        dg ........
                        dg ........

; Character widths

PrintWidths             defb $07,$09,$09,$09,$09,$09,$09,$03
                        defb $05,$05,$05,$05,$03,$05,$05,$05
                        defb $05,$03,$05,$05,$05,$05,$09,$09 ; " " ..
                        defb $07,$09,$07,$02,$05,$09,$07,$09
                        defb $06,$02,$04,$06,$06,$06,$06,$02
                        defb $04,$04,$06,$06,$03,$06,$02,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$02,$03,$05,$06,$05,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$04,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$04,$06
                        defb $06,$02,$04,$06,$04,$06,$06,$06
                        defb $06,$06,$05,$06,$06,$06,$06,$06
                        defb $06,$05,$06,$05,$02,$05,$06,$06
                        defb $03,$06,$0C,$12,$18,$1E,$24,$2A  ; Wide spaces $80..?
                        defb $30,$36,$3C,$42,$48,$06,$06,$06
                        defb $01,$02,$03,$04,$05,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06
                        defb $06,$06,$06,$06,$06,$06,$06,$06

; Variables

pCurX                   db 0                            ; A logical X position
ppCurY                  db 0                            ; A logical Y position
pCurY                   dw 0                            ; The actual address
CurCol                  db 0                            ; The cursor colour
Value                   dw 0                            ; A variable

; Space for the stack

                        ds $100                         ;
Stack                   equ *                           ;

; We must tell the emulator what it's allowed to do

                        mem_var $4000,$1B00             ; The Spectrum screen is variable
                        mem_var pCurX,* - pCurX         ; This block is writable




