Crap 0.1 first assembly project

Show us what you're working on, (preferably with screenshots).
Post Reply
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

EOBOARD: EQU $ needs to be after the board data, and before the HELPBOARD: label.

At the end of your main loop, you're jumping back to the help printing text every time. Instead:

Code: Select all

MAINLOOP:
       CALL GAMELOOP
       ;CALL KEYBOARDINPUT
       JP MAINLOOP
Last edited by Seven.FFF on Wed Jan 24, 2018 6:01 pm, edited 1 time in total.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Nomad wrote: Wed Jan 24, 2018 5:34 pmWhat do they actually do anyway?
The ROM print routine at 8252 takes the address of the first byte of the data in de, and the number of bytes to print (length) in bc.

You're using the assembler to do the maths heavy lifting by calculating the length, in such a way that there aren't any magic address numbers in the code. The code could be relocated by changing ORG, at any time, without breaking anything (all other things being equal).

$ will be the address of the byte after the last piece of data, at the time EOHELP etc is defined. Think of a simple example:

org 40000
TEST:
40000 db 'A'
40001 db 'B'
40002 db 'C'
EOTEST equ $
40003 [...]

TEST is 40000
EOTEST is 40003

EOTEST-TEST = 40003-40000 = 3 = the number of data bytes.

All more perils of copying examples by rote :D You'd usually do this deliberately, because you wanted to do the address and calculations. But getting the cart before the horse, you're doing calculations you don't understand the purpose of, and your confusion is even worse than if you'd used magic numbers and got them mixed up.
Last edited by Seven.FFF on Wed Jan 24, 2018 6:02 pm, edited 1 time in total.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Another step towards eliminating magic numbers and confusion would be to do:

PR_STRING equ 8252

And use that constant everywhere instead of 8252. It's a) the official name of the routine in the ROM, so other people reading the code have a common reference point, and b) reasonably self-descriptive in itself. :)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

More constants I use a lot, which would help make the print data more readable:

Code: Select all

; Screen
PixelAddress            equ $4000
AttributeAddress        equ $5800                       ; Start of the attributes in the Spectrum display file
AttributeLength         equ $300                        ; There are 768 bytes of attributes
BS                      equ 8
CR                      equ 13
Ink                     equ 16
Paper                   equ 17
Flash                   equ 18
Dim                     equ %00000000                   ; These two constants are the
Bright                  equ %01000000                   ;   attribute mask for the bright flag
PrBright                equ 19                          ; This is the print code for BRIGHT for ROM routines
Inverse                 equ 20
Over                    equ 21
At                      equ 22                          ; FZX understands this one as well as the ROM routines
Tab                     equ 23
Black                   equ 0
Blue                    equ 1
Red                     equ 2
Magenta                 equ 3
Green                   equ 4
Cyan                    equ 5
Yellow                  equ 6
White                   equ 7
BlackP                  equ 8*Black
BlueP                   equ 8*Blue
RedP                    equ 8*Red
MagentaP                equ 8*Magenta
GreenP                  equ 8*Green
CyanP                   equ 8*Cyan
YellowP                 equ 8*Yellow
WhiteP                  equ 8*White
DimBlack                equ Black
DimBlue                 equ Blue
DimRed                  equ Red
DimMagenta              equ Magenta
DimGreen                equ Green
DimCyan                 equ Cyan
DimYellow               equ Yellow
DimWhite                equ White
BrightBlack             equ Black+Bright
BrightBlue              equ Blue+Bright
BrightRed               equ Red+Bright
BrightMagenta           equ Magenta+Bright
BrightGreen             equ Green+Bright
BrightCyan              equ Cyan+Bright
BrightYellow            equ Yellow+Bright
BrightWhite             equ White+Bright
DimBlackBlackP          equ DimBlack+BlackP
DimBlueBlackP           equ DimBlue+BlackP
DimRedBlackP            equ DimRed+BlackP
DimMagentaBlackP        equ DimMagenta+BlackP
DimGreenBlackP          equ DimGreen+BlackP
DimCyanBlackP           equ DimCyan+BlackP
DimYellowBlackP         equ DimYellow+BlackP
DimWhiteBlackP          equ DimWhite+BlackP
BrightBlackBlackP       equ BrightBlack+BlackP
BrightBlueBlackP        equ BrightBlue+BlackP
BrightRedBlackP         equ BrightRed+BlackP
BrightMagentaBlackP     equ BrightMagenta+BlackP
BrightGreenBlackP       equ BrightGreen+BlackP
BrightCyanBlackP        equ BrightCyan+BlackP
BrightYellowBlackP      equ BrightYellow+BlackP
BrightWhiteBlackP       equ BrightWhite+BlackP
DimBlackBlueP           equ DimBlack+BlueP
DimBlueBlueP            equ DimBlue+BlueP
DimRedBlueP             equ DimRed+BlueP
DimMagentaBlueP         equ DimMagenta+BlueP
DimGreenBlueP           equ DimGreen+BlueP
DimCyanBlueP            equ DimCyan+BlueP
DimYellowBlueP          equ DimYellow+BlueP
DimWhiteBlueP           equ DimWhite+BlueP
BrightBlackBlueP        equ BrightBlack+BlueP
BrightBlueBlueP         equ BrightBlue+BlueP
BrightRedBlueP          equ BrightRed+BlueP
BrightMagentaBlueP      equ BrightMagenta+BlueP
BrightGreenBlueP        equ BrightGreen+BlueP
BrightCyanBlueP         equ BrightCyan+BlueP
BrightYellowBlueP       equ BrightYellow+BlueP
BrightWhiteBlueP        equ BrightWhite+BlueP
DimBlackRedP            equ DimBlack+RedP
DimBlueRedP             equ DimBlue+RedP
DimRedRedP              equ DimRed+RedP
DimMagentaRedP          equ DimMagenta+RedP
DimGreenRedP            equ DimGreen+RedP
DimCyanRedP             equ DimCyan+RedP
DimYellowRedP           equ DimYellow+RedP
DimWhiteRedP            equ DimWhite+RedP
BrightBlackRedP         equ BrightBlack+RedP
BrightBlueRedP          equ BrightBlue+RedP
BrightRedRedP           equ BrightRed+RedP
BrightMagentaRedP       equ BrightMagenta+RedP
BrightGreenRedP         equ BrightGreen+RedP
BrightCyanRedP          equ BrightCyan+RedP
BrightYellowRedP        equ BrightYellow+RedP
BrightWhiteRedP         equ BrightWhite+RedP
DimBlackMagentaP        equ DimBlack+MagentaP
DimBlueMagentaP         equ DimBlue+MagentaP
DimRedMagentaP          equ DimRed+MagentaP
DimMagentaMagentaP      equ DimMagenta+MagentaP
DimGreenMagentaP        equ DimGreen+MagentaP
DimCyanMagentaP         equ DimCyan+MagentaP
DimYellowMagentaP       equ DimYellow+MagentaP
DimWhiteMagentaP        equ DimWhite+MagentaP
BrightBlackMagentaP     equ BrightBlack+MagentaP
BrightBlueMagentaP      equ BrightBlue+MagentaP
BrightRedMagentaP       equ BrightRed+MagentaP
BrightMagentaMagentaP   equ BrightMagenta+MagentaP
BrightGreenMagentaP     equ BrightGreen+MagentaP
BrightCyanMagentaP      equ BrightCyan+MagentaP
BrightYellowMagentaP    equ BrightYellow+MagentaP
BrightWhiteMagentaP     equ BrightWhite+MagentaP
DimBlackGreenP          equ DimBlack+GreenP
DimBlueGreenP           equ DimBlue+GreenP
DimRedGreenP            equ DimRed+GreenP
DimMagentaGreenP        equ DimMagenta+GreenP
DimGreenGreenP          equ DimGreen+GreenP
DimCyanGreenP           equ DimCyan+GreenP
DimYellowGreenP         equ DimYellow+GreenP
DimWhiteGreenP          equ DimWhite+GreenP
BrightBlackGreenP       equ BrightBlack+GreenP
BrightBlueGreenP        equ BrightBlue+GreenP
BrightRedGreenP         equ BrightRed+GreenP
BrightMagentaGreenP     equ BrightMagenta+GreenP
BrightGreenGreenP       equ BrightGreen+GreenP
BrightCyanGreenP        equ BrightCyan+GreenP
BrightYellowGreenP      equ BrightYellow+GreenP
BrightWhiteGreenP       equ BrightWhite+GreenP
DimBlackCyanP           equ DimBlack+CyanP
DimBlueCyanP            equ DimBlue+CyanP
DimRedCyanP             equ DimRed+CyanP
DimMagentaCyanP         equ DimMagenta+CyanP
DimGreenCyanP           equ DimGreen+CyanP
DimCyanCyanP            equ DimCyan+CyanP
DimYellowCyanP          equ DimYellow+CyanP
DimWhiteCyanP           equ DimWhite+CyanP
BrightBlackCyanP        equ BrightBlack+CyanP
BrightBlueCyanP         equ BrightBlue+CyanP
BrightRedCyanP          equ BrightRed+CyanP
BrightMagentaCyanP      equ BrightMagenta+CyanP
BrightGreenCyanP        equ BrightGreen+CyanP
BrightCyanCyanP         equ BrightCyan+CyanP
BrightYellowCyanP       equ BrightYellow+CyanP
BrightWhiteCyanP        equ BrightWhite+CyanP
DimBlackYellowP         equ DimBlack+YellowP
DimBlueYellowP          equ DimBlue+YellowP
DimRedYellowP           equ DimRed+YellowP
DimMagentaYellowP       equ DimMagenta+YellowP
DimGreenYellowP         equ DimGreen+YellowP
DimCyanYellowP          equ DimCyan+YellowP
DimYellowYellowP        equ DimYellow+YellowP
DimWhiteYellowP         equ DimWhite+YellowP
BrightBlackYellowP      equ BrightBlack+YellowP
BrightBlueYellowP       equ BrightBlue+YellowP
BrightRedYellowP        equ BrightRed+YellowP
BrightMagentaYellowP    equ BrightMagenta+YellowP
BrightGreenYellowP      equ BrightGreen+YellowP
BrightCyanYellowP       equ BrightCyan+YellowP
BrightYellowYellowP     equ BrightYellow+YellowP
BrightWhiteYellowP      equ BrightWhite+YellowP
DimBlackWhiteP          equ DimBlack+WhiteP
DimBlueWhiteP           equ DimBlue+WhiteP
DimRedWhiteP            equ DimRed+WhiteP
DimMagentaWhiteP        equ DimMagenta+WhiteP
DimGreenWhiteP          equ DimGreen+WhiteP
DimCyanWhiteP           equ DimCyan+WhiteP
DimYellowWhiteP         equ DimYellow+WhiteP
DimWhiteWhiteP          equ DimWhite+WhiteP
BrightBlackWhiteP       equ BrightBlack+WhiteP
BrightBlueWhiteP        equ BrightBlue+WhiteP
BrightRedWhiteP         equ BrightRed+WhiteP
BrightMagentaWhiteP     equ BrightMagenta+WhiteP
BrightGreenWhiteP       equ BrightGreen+WhiteP
BrightCyanWhiteP        equ BrightCyan+WhiteP
BrightYellowWhiteP      equ BrightYellow+WhiteP
BrightWhiteWhiteP       equ BrightWhite+WhiteP
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Thanks for your constants list :) your right it does make it more readable.. Not sure about the camel case haha. Will have a think about that next time.

Yes I know FATFONT and FAT_FONT are not the most readable of labels lol..

Still its looking better than it did, now .. the grid dissipaters. hmmm interesting.

Going to put my potato brain to bed for the day, lol you never know what might happen with a little bit of zzzz.

Code: Select all

ORG 33000
; Screen
PixelAddress            equ $4000
AttributeAddress        equ $5800                       ; Start of the attributes in the Spectrum display file
AttributeLength         equ $300                        ; There are 768 bytes of attributes
BS                      equ 8
CR                      equ 13
Ink                     equ 16
Paper                   equ 17
Flash                   equ 18
Dim                     equ %00000000                   ; These two constants are the
Bright                  equ %01000000                   ;   attribute mask for the bright flag
PrBright                equ 19                          ; This is the print code for BRIGHT for ROM routines
Inverse                 equ 20
Over                    equ 21
At                      equ 22                          ; FZX understands this one as well as the ROM routines
Tab                     equ 23
Black                   equ 0
Blue                    equ 1
Red                     equ 2
Magenta                 equ 3
Green                   equ 4
Cyan                    equ 5
Yellow                  equ 6
White                   equ 7
BlackP                  equ 8*Black
BlueP                   equ 8*Blue
RedP                    equ 8*Red
MagentaP                equ 8*Magenta
GreenP                  equ 8*Green
CyanP                   equ 8*Cyan
YellowP                 equ 8*Yellow
WhiteP                  equ 8*White
DimBlack                equ Black
DimBlue                 equ Blue
DimRed                  equ Red
DimMagenta              equ Magenta
DimGreen                equ Green
DimCyan                 equ Cyan
DimYellow               equ Yellow
DimWhite                equ White
BrightBlack             equ Black+Bright
BrightBlue              equ Blue+Bright
BrightRed               equ Red+Bright
BrightMagenta           equ Magenta+Bright
BrightGreen             equ Green+Bright
BrightCyan              equ Cyan+Bright
BrightYellow            equ Yellow+Bright
BrightWhite             equ White+Bright
DimBlackBlackP          equ DimBlack+BlackP
DimBlueBlackP           equ DimBlue+BlackP
DimRedBlackP            equ DimRed+BlackP
DimMagentaBlackP        equ DimMagenta+BlackP
DimGreenBlackP          equ DimGreen+BlackP
DimCyanBlackP           equ DimCyan+BlackP
DimYellowBlackP         equ DimYellow+BlackP
DimWhiteBlackP          equ DimWhite+BlackP
BrightBlackBlackP       equ BrightBlack+BlackP
BrightBlueBlackP        equ BrightBlue+BlackP
BrightRedBlackP         equ BrightRed+BlackP
BrightMagentaBlackP     equ BrightMagenta+BlackP
BrightGreenBlackP       equ BrightGreen+BlackP
BrightCyanBlackP        equ BrightCyan+BlackP
BrightYellowBlackP      equ BrightYellow+BlackP
BrightWhiteBlackP       equ BrightWhite+BlackP
DimBlackBlueP           equ DimBlack+BlueP
DimBlueBlueP            equ DimBlue+BlueP
DimRedBlueP             equ DimRed+BlueP
DimMagentaBlueP         equ DimMagenta+BlueP
DimGreenBlueP           equ DimGreen+BlueP
DimCyanBlueP            equ DimCyan+BlueP
DimYellowBlueP          equ DimYellow+BlueP
DimWhiteBlueP           equ DimWhite+BlueP
BrightBlackBlueP        equ BrightBlack+BlueP
BrightBlueBlueP         equ BrightBlue+BlueP
BrightRedBlueP          equ BrightRed+BlueP
BrightMagentaBlueP      equ BrightMagenta+BlueP
BrightGreenBlueP        equ BrightGreen+BlueP
BrightCyanBlueP         equ BrightCyan+BlueP
BrightYellowBlueP       equ BrightYellow+BlueP
BrightWhiteBlueP        equ BrightWhite+BlueP
DimBlackRedP            equ DimBlack+RedP
DimBlueRedP             equ DimBlue+RedP
DimRedRedP              equ DimRed+RedP
DimMagentaRedP          equ DimMagenta+RedP
DimGreenRedP            equ DimGreen+RedP
DimCyanRedP             equ DimCyan+RedP
DimYellowRedP           equ DimYellow+RedP
DimWhiteRedP            equ DimWhite+RedP
BrightBlackRedP         equ BrightBlack+RedP
BrightBlueRedP          equ BrightBlue+RedP
BrightRedRedP           equ BrightRed+RedP
BrightMagentaRedP       equ BrightMagenta+RedP
BrightGreenRedP         equ BrightGreen+RedP
BrightCyanRedP          equ BrightCyan+RedP
BrightYellowRedP        equ BrightYellow+RedP
BrightWhiteRedP         equ BrightWhite+RedP
DimBlackMagentaP        equ DimBlack+MagentaP
DimBlueMagentaP         equ DimBlue+MagentaP
DimRedMagentaP          equ DimRed+MagentaP
DimMagentaMagentaP      equ DimMagenta+MagentaP
DimGreenMagentaP        equ DimGreen+MagentaP
DimCyanMagentaP         equ DimCyan+MagentaP
DimYellowMagentaP       equ DimYellow+MagentaP
DimWhiteMagentaP        equ DimWhite+MagentaP
BrightBlackMagentaP     equ BrightBlack+MagentaP
BrightBlueMagentaP      equ BrightBlue+MagentaP
BrightRedMagentaP       equ BrightRed+MagentaP
BrightMagentaMagentaP   equ BrightMagenta+MagentaP
BrightGreenMagentaP     equ BrightGreen+MagentaP
BrightCyanMagentaP      equ BrightCyan+MagentaP
BrightYellowMagentaP    equ BrightYellow+MagentaP
BrightWhiteMagentaP     equ BrightWhite+MagentaP
DimBlackGreenP          equ DimBlack+GreenP
DimBlueGreenP           equ DimBlue+GreenP
DimRedGreenP            equ DimRed+GreenP
DimMagentaGreenP        equ DimMagenta+GreenP
DimGreenGreenP          equ DimGreen+GreenP
DimCyanGreenP           equ DimCyan+GreenP
DimYellowGreenP         equ DimYellow+GreenP
DimWhiteGreenP          equ DimWhite+GreenP
BrightBlackGreenP       equ BrightBlack+GreenP
BrightBlueGreenP        equ BrightBlue+GreenP
BrightRedGreenP         equ BrightRed+GreenP
BrightMagentaGreenP     equ BrightMagenta+GreenP
BrightGreenGreenP       equ BrightGreen+GreenP
BrightCyanGreenP        equ BrightCyan+GreenP
BrightYellowGreenP      equ BrightYellow+GreenP
BrightWhiteGreenP       equ BrightWhite+GreenP
DimBlackCyanP           equ DimBlack+CyanP
DimBlueCyanP            equ DimBlue+CyanP
DimRedCyanP             equ DimRed+CyanP
DimMagentaCyanP         equ DimMagenta+CyanP
DimGreenCyanP           equ DimGreen+CyanP
DimCyanCyanP            equ DimCyan+CyanP
DimYellowCyanP          equ DimYellow+CyanP
DimWhiteCyanP           equ DimWhite+CyanP
BrightBlackCyanP        equ BrightBlack+CyanP
BrightBlueCyanP         equ BrightBlue+CyanP
BrightRedCyanP          equ BrightRed+CyanP
BrightMagentaCyanP      equ BrightMagenta+CyanP
BrightGreenCyanP        equ BrightGreen+CyanP
BrightCyanCyanP         equ BrightCyan+CyanP
BrightYellowCyanP       equ BrightYellow+CyanP
BrightWhiteCyanP        equ BrightWhite+CyanP
DimBlackYellowP         equ DimBlack+YellowP
DimBlueYellowP          equ DimBlue+YellowP
DimRedYellowP           equ DimRed+YellowP
DimMagentaYellowP       equ DimMagenta+YellowP
DimGreenYellowP         equ DimGreen+YellowP
DimCyanYellowP          equ DimCyan+YellowP
DimYellowYellowP        equ DimYellow+YellowP
DimWhiteYellowP         equ DimWhite+YellowP
BrightBlackYellowP      equ BrightBlack+YellowP
BrightBlueYellowP       equ BrightBlue+YellowP
BrightRedYellowP        equ BrightRed+YellowP
BrightMagentaYellowP    equ BrightMagenta+YellowP
BrightGreenYellowP      equ BrightGreen+YellowP
BrightCyanYellowP       equ BrightCyan+YellowP
BrightYellowYellowP     equ BrightYellow+YellowP
BrightWhiteYellowP      equ BrightWhite+YellowP
DimBlackWhiteP          equ DimBlack+WhiteP
DimBlueWhiteP           equ DimBlue+WhiteP
DimRedWhiteP            equ DimRed+WhiteP
DimMagentaWhiteP        equ DimMagenta+WhiteP
DimGreenWhiteP          equ DimGreen+WhiteP
DimCyanWhiteP           equ DimCyan+WhiteP
DimYellowWhiteP         equ DimYellow+WhiteP
DimWhiteWhiteP          equ DimWhite+WhiteP
BrightBlackWhiteP       equ BrightBlack+WhiteP
BrightBlueWhiteP        equ BrightBlue+WhiteP
BrightRedWhiteP         equ BrightRed+WhiteP
BrightMagentaWhiteP     equ BrightMagenta+WhiteP
BrightGreenWhiteP       equ BrightGreen+WhiteP
BrightCyanWhiteP        equ BrightCyan+WhiteP
BrightYellowWhiteP      equ BrightYellow+WhiteP
BrightWhiteWhiteP       equ BrightWhite+WhiteP

PR_STRING equ 8252
LAST_K    equ 23560
ROM_FONT  equ 15616
FAT_FONT  equ 60000
SET_BORDER equ 8859
CLEAR_SCR equ 3503       

MAIN:
       CALL FATFONT
       LD A,DimWhiteBlueP     ; 
       LD (23693),A         
       LD A,1
       CALL SET_BORDER     ; SET BORDER
       CALL CLEAR_SCR      ; CLEAR SCREEN & SET PAPER N INK.
       CALL HELPSCREEN
 MGL:  CALL KEYBOARDINPUT
       CALL GAMELOOP
       CALL KEYBOARDINPUT
       JP MGL

HELPSCREEN:
       ld a,2              ; upper screen
       call 5633           ; open channel
       ld de,HELP        ; address of string
       ld bc,EOSTR1-HELP  ; length of string to print
       call PR_STRING       ; print our string
       LD DE,HELPBOARD
       LD BC,EOSTR2-HELPBOARD
       CALL PR_STRING
       RET

FATFONT:
       ld hl,ROM_FONT      ; ROM font.
       ld de,FAT_FONT      ; address of our font.
       ld bc,768           ; 96 chars * 8 rows to alter.
font1  ld a,(hl)           ; get bitmap.
       rlca                ; rotate it left.
       or (hl)             ; combine 2 images.
       ld (de),a           ; write to new font.
       inc hl              ; next byte of old.
       inc de              ; next byte of new.
       dec bc              ; decrement counter.
       ld a,b              ; high byte.
       or c                ; combine with low byte.
       jr nz,font1         ; repeat until bc=zero.
       ld hl,FAT_FONT-256  ; font minus 32*8.
       ld (23606),hl       ; point to new font.
       ret

KEYBOARDINPUT:
       ld hl,LAST_K         ; LAST K system variable.
       ld (hl),0           ; put null value there.
_loop   ld a,(hl)           ; new value of LAST K.
       cp 0                ; is it still zero?
       jr z,_loop           ; yes, so no key pressed.
       RET                          ; key was pressed.

GAMELOOP:
       ld a,2              ; upper screen
       call 5633           ; open channel
       ld de,HELP        ; address of string
       ld bc,EOSTR1-HELP  ; length of string to print
       call PR_STRING 
       LD DE,BOARD
       LD BC,EOSTR3-BOARD
       CALL PR_STRING
       RET

HELP:  DEFB Ink,Black,At,1,6,Paper,9,'*',Paper,Magenta,' ',Paper,Red,'N',Paper,Magenta,'o',Paper,Green,'u',Paper,5,'g',Paper,6,'h',Paper,White,'t',Paper,Red,'s',Paper,5,' ',Paper,Magenta,'&',Paper,Magenta,' ',Paper,Green,'C',Paper,5,'r',Paper,6,'o',Paper,White,'s',Paper,Red,'s',Paper,5,'e',Paper,White,'s',Paper,Magenta,' ',Paper,Green,'*'
       DEFB Ink,White,At,4,15,Paper,1,'This is noughts',CR
       DEFB At,5,15,'and crosses, for',CR 
       DEFB At,6,15,'two players.',CR 
       DEFB At,8,15,'I will tell you',CR
       DEFB At,9,15,'when either of',CR 
       DEFB At,10,15,'you has won.',CR
       DEFB At,12,15,'The board is',CR
       DEFB At,13,15,'numbered as on',CR
       DEFB At,14,15,'the left side',CR
       DEFB At,15,15,'of the screen.',CR
       DEFB At,21,2,'PRESS ',Flash,1,Ink,Red,'<RETURN>',Flash,0,Ink,White,' TO CONTINUE...'
EOSTR1: equ $

BOARD: DEFB Ink,Red,Paper,Black,At,4,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,5,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,6,1,$8A,' ',Ink,Black,$80,Ink,Red,' ',$8A,' ',Ink,Black,$80,Ink,Red,' ',$85,' ',Ink,Black,$80,Ink,Red,' ',$85,CR
       DEFB At,7,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,8,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,9,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,10,1,$8A,' ',Ink,Black,$80,Ink,Red,' ',$8A,' ',Ink,Black,$80,Ink,Red,' ',$85,' ',Ink,Black,$80,Ink,Red,' ',$85,CR
       DEFB At,11,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,12,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,13,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,14,1,$8A,' ',Ink,Black,$80,Ink,Red,' ',$8A,' ',Ink,Black,$80,Ink,Red,' ',$85,' ',Ink,Black,$80,Ink,Red,' ',$85,CR
       DEFB At,15,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,16,1,$8E,$8C,$8C,$8C,$8E,$8C,$8C,$8C,$8D,$8C,$8C,$8C,$8D,CR,Paper,Blue,Ink,White
EOSTR2: equ $

HELPBOARD:
       DEFB Ink,Red,Paper,Black,At,4,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,5,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,6,1,$8A,' ',Ink,Magenta,'1',Ink,Red,' ',$8A,' ',Ink,Magenta,'2',Ink,Red,' ',$85,' ',Ink,Magenta,'3',Ink,Red,' ',$85,CR
       DEFB At,7,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,8,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,9,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,10,1,$8A,' ',Ink,Magenta,'4',Ink,Red,' ',$8A,' ',Ink,Magenta,'5',Ink,Red,' ',$85,' ',Ink,Magenta,'6',Ink,Red,' ',$85,CR
       DEFB At,11,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,12,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,CR
       DEFB At,13,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,14,1,$8A,' ',Ink,Magenta,'7',Ink,Red,' ',$8A,' ',Ink,Magenta,'8',Ink,Red,' ',$85,' ',Ink,Magenta,'9',Ink,Red,' ',$85,CR
       DEFB At,15,1,$8A,'   ',$8A,'   ',$85,'   ',$85,CR
       DEFB At,16,1,$8E,$8C,$8C,$8C,$8E,$8C,$8C,$8C,$8D,$8C,$8C,$8C,$8D,13,Paper,Blue,Ink,White
EOSTR3: equ $

END MAIN
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Having slept on the problem, looking at the code afresh and re factoring it. I discovered I was being a dummy. :lol: I had zigged when I should have zagged. As was pointed out. I had jumbled up my fancy string length calculations. Assuming anything else equally potato does not crop up (highly likely unfortunately...) Predicting that end of the day will see the noughts and crosses program finished.

These keyboard input routines are getting on my nips lol. The multikey input routine is so flakey sometimes it works, sometimes it does not. there is no predictability other than it wont function reliably.

Then there is the test key, it seems a bit more reliable but then its useless for my task because I need to test 1-9 key at the same time.

is there a reliable, responsive way to do this?

Code: Select all

KEYBOARDINPUT:
       LD HL,LAST_K         ; LAST K SYSTEM VARIABLE.
       LD (HL),0           ; PUT NULL VALUE THERE.
_LOOP   LD A,(HL)           ; NEW VALUE OF LAST K.
       CP 0                ; IS IT STILL ZERO?
       JR Z,_LOOP           ; YES, SO NO KEY PRESSED.
       RET                          ; KEY WAS PRESSED.

MULTIKEY:
; WE WANT TO SCAN KEY 1-9, SO THE FOLLOWING WILL BE USED.

;61438 6, 7, 8, 9, 0
;63486 5, 4, 3, 2, 1
	LD A,0
	LD BC,63438         ; KEYBOARD ROW 6-0/JOYSTICK PORT 2.
       	IN A,(C)            ; SEE WHAT KEYS ARE PRESSED.
	RRA                 ; NEXT BIT ALONG (VALUE 2) = KEY 9.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP9         ; BEING PRESSED, SO PUT COUNTER IN MP9.
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 4) = KEY 8.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP8         ; BEING PRESSED,  SO PUT COUNTER IN MP8.
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 8) READS KEY 7.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP7         ; IT'S BEING PRESSED,  SO PUT COUNTER IN MP7.
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 16) READS KEY 6.
	CALL NC,MP6         ; IT'S BEING PRESSED,  SO PUT COUNTER IN MP6.
	LD A,0
	LD BC,63486         ; KEYBOARD ROW 1-5/JOYSTICK PORT 2.
       	IN A,(C)            ; SEE WHAT KEYS ARE PRESSED.
	RRA                 ; OUTERMOST BIT = KEY 1.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP1         ; IT'S BEING PRESSED,  SO PUT COUNTER IN MP1.
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT ALONG (VALUE 2) = KEY 2.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP2         ; BEING PRESSED, SO  SO PUT COUNTER IN MP2.
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 4) = KEY 3.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP3         ; BEING PRESSED,  SO PUT COUNTER IN MP3
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 8) READS KEY 4.
	PUSH AF             ; REMEMBER THE VALUE.
	CALL NC,MP4         ; IT'S BEING PRESSED,  SO PUT COUNTER IN MP4
	POP AF              ; RESTORE ACCUMULATOR.
	RRA                 ; NEXT BIT (VALUE 16) READS KEY 5.
	CALL NC,MP5         ; IT'S BEING PRESSED,  SO PUT COUNTER IN MP5
	JP Z,MULTIKEY
	RET

KEYTEST:
; MR. JONES' KEYBOARD TEST ROUTINE.

KTEST  LD C,A              ; KEY TO TEST IN C.
       AND 7               ; MASK BITS D0-D2 FOR ROW.
       INC A               ; IN RANGE 1-8.
       LD B,A              ; PLACE IN B.
       SRL C               ; DIVIDE C BY 8,
       SRL C               ; TO FIND POSITION WITHIN ROW.
       SRL C
       LD A,5              ; ONLY 5 KEYS PER ROW.
       SUB C               ; SUBTRACT POSITION.
       LD C,A              ; PUT IN C.
       LD A,254            ; HIGH BYTE OF PORT TO READ.
KTEST0 RRCA                ; ROTATE INTO POSITION.
       DJNZ KTEST0         ; REPEAT UNTIL WE'VE FOUND RELEVANT ROW.
       IN A,(254)          ; READ PORT (A=HIGH, 254=LOW).
KTEST1 RRA                 ; ROTATE BIT OUT OF RESULT.
       DEC C               ; LOOP COUNTER.
       JP NZ,KTEST1        ; REPEAT UNTIL BIT FOR POSITION IN CARRY.
       CCF
       RET
With MULTIKEY I tried resetting the accumulator between port scans, but that does not seem to help much. This is the main keyboard input i was trying to get working.

KEYBOARDINPUT works just fine, always responds and behaves in a predictable way. But then its not performing a particularly demanding task.. It's the one you would expect to work fine.

KEYTEST seems not to be so reliable.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Figured when the copy pasta failed me it was time to actually use my own coconut and 'roll my own' keyboard input comparator.

Code: Select all

POTATOK:
	LD A,0
	LD A,(LAST_K)
	CP $31		; IS 1?
	JP Z,MP1	; JUMP TO MP1
	CP $32		; IS 2?
	JP Z,MP2	; JUMP TO MP2
	CP $33		; IS 3?
	JP Z,MP3	; JUMP TO MP3
	CP $34		; IS 4?
	JP Z,MP4	; JUMP TO MP4
	CP $35		; IS 5?
	JP Z,MP5	; JUMP TO MP5
	CP $36		; IS 6?
	JP Z,MP6	; JUMP TO MP6
	CP $37		; IS 7?
	JP Z,MP7	; JUMP TO MP7
	CP $38		; IS 8?
	JP Z,MP8	; JUMP TO MP8
	CP $39		; IS 9?
	JP Z,MP9	; JUMP TO MP9
	RET
This works much more predictably than the copy and pasted subroutines. However the only pain in the butt is its not like INKEY$ in that I have to hit the key twice to get a response.

But for now its ok, at least it has limited predictable functionality. Will figure out what is wrong later.


Found out what the problem was, I was calling the KEYBOARDINPUT subroutine directly after the POTATOK subrouitne. (thus accounting for why I was having to hit everything twice..)
Having removed this from the main loop keyboard input responds as expected and is reliable.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 25: 340 days left.

As can be seen by my earlier comments today, POTATOK is working just fine and I can get information from the keyboard. I had been trying for days to get the tutorial keyboard routines to work without much success. I don't know what I was doing wrong there or if it was a case of them being non-portable. (lol wouldn't be the first tutorial that used a non-general routine example and stayed quiet about the fact...)

Anyway all that time wasted when I should have just trusted myself and wrote out my own routine. The funny thing was it worked first time (I just didn't realise it), another keyboard routine was causing the problem. I was using the general key test subroutine as a sanity check earlier in the day and had forgotten to take it out.

Still I think that the CP ladders are not the best solution, I think there is a more elegant approach but this was the simple one.

Once the keyboard input was done, I figured just cheeze this and use UGL characters for the noughts and crosses, its still better than the MSX basic listing at this point meh.. the idea was just to get something working then make it 'beautiful'. So I resisted the urge to break out SevenUP and get sprite happy for the moment.

From this point it was trivial to use the SOUNDFX.ASM file I had from crapchess in the project. I like this part about having the multi-file project. Now it's much more like a real program and it literally took me 1 min to include the file and call the routines. I think in the future this approach will greatly increase my productivity as I can be sure that the routines in the libraries work I just have to call them correctly.

Thus the keyboard input routines that were working all now live in KEYBOARD.ASM. Happily I can now use this in the crapchess with a little bit of work (just add in A,B,C,D,E,F,G,H and the arrow keys and were cooking on gas!)

As far as work flow goes, I tend to do the prototyping of ideas in MSX basic as I find it easer to use than spectrum basic. being able to something working straight off the bat (abet slow). Is good. From there I think about if I can feasibly do this on the spectrum in assembly. Then start figuring out the equivalent subroutines needed and if I already have written or have swiped from others or I will need to find/write them.

With the noughts and crosses the listing was 90 lines of basic, no graphics and just text characters to show the board. Speed wise its got the flicker issue that you find with most basic programs that update the screen.

I thought that with assembly code this could be fast enough to be fixed. and with fancy (er) graphics and some sounds, intro screen to tart it up a bit.

The program logic is an array, when a player selects a position on the board to place the X or the O the computer checks if that location is already occupied. If its already taken, an error is raised and the user is asked to input another choice. This continues in a loop till the program gets a board location that is vacant. It then places the O or X on the screen and records the players value in the array location (1-9).

There can be a maximum of 9 possible moves in noughts and crosses, there are three possible outcomes assuming that the players do not abandon the game.

1. Player A wins, Player B looses. No draw.
2. Player A looses, Player B wins. No draw.
3. Player A looses, Player B looses. Draw. (really this should be a case where A and B cant win..)

The basic listing looks at the array locations and sums them, if a certain magic number is reached it will tell you that a win state has happened (3 in a row). Based upon who has taken the last move tells the program who has won.

e.g

if CURRENTPLAYER = A then if any of the array lines sum to the winning total (3) goto winner section of the code.

This is fairly straight forward to do in assembly, my solution was to just have a series of nine memory locations that can be peeked by the program during run time. every time player A or B puts down a O or X a value is entered into these memory locations (in my program they live at 60001 -> 60009. with 2 being player B and 1 being player 1.

my solution to checking if there was already a value in the memory location is simple I just load the memory location into the accumulator compare it if its not zero then branch to an error state. tell the player they can't place a O or X in that location (1-9) and try again. This can be achieved in the form of a CP block of code with a JP to a error subroutine., then finally just a jp back to the start of the input loop.

The valid location selection is simple, assuming that the memory location that the player selected via keyboard (1-9) is 0, then either a 1 or a 2 is placed into the memory location. This is important as I use the 1,0,2 to determine what to print on the screen during the screen update portion of the program.

1 being an X and 2 being the O. blank space is 0. This is just another CP ladder that checks the memory location 60001 -> 60009 and prints to the screen.

The logic is fairly similar to the basic for checking win states, the memory locations are summed then logic is used (a series of AND and ORs should do the trick). if any of these logic states prove true then the program ends in one of the three ways I described earlier and depending on what state the program is in at the end determines how the screen looks to the user (Player A win screen, Player B win screen, Draw)

At the end of the game - there is a key input if players want to play again they can hit Y or if they want to continue on with their lives without more Noughts and Crosses action they can hit N. This is just another keyboard input routine. Would just be a variation of my POTATO routine (POTATOK3) that only checks for Y or N and berates you if you pick another key outside the range.

The last part is interesting, I plan to crash the machine on exit if user selects N.

There - a design outline for a assembly language noughts and crosses game. The reasons for creating such a think dubious at best but sometimes its best to get something done even if its crap and build up the skills haha. And what was obvious was I needed some more work before I can get crap chess working. But now that the noughts and crosses is nearly complete it makes me more confident in tackling crapchess and being able to complete it also.

Its the subroutines that I can use on the other projects that are the important thing, routines I can use again and again that are guaranteed to work out of the box. My prediction is soon this will enable me to increase my output. I figure there is a tipping point where you have enough subroutines in the bag to create any similar game you want then its just a matter of a graphics swap and some minor adjustment of game logic and you are good to go. With the board games I am only really limited by my lack of ability in scrolling the screen at the moment. If I just focus on non scrolling board games then that presents many hundreds of possible games that can be coded.

Snakes and ladders was one I thought about doing but unless I was going to make the squares very small its not fees able without scrolling the screen. So that is something for later. But boardgame geek has hundreds of games just waiting to a chance in the 'product lineup' lol. I always wanted to see how quickly I could bang out a line of games like this. If someone had a library of routines I think a great many could be created. Its just limited by your time in graphics for the different games. But then once you have a few graphics done its not hard to adapt for a new game. And then its just title screens and the help text.

The board games have been played by generations of people so its already play tested and a big part of the work is done then. While not technically impressive at least its a playable game. Lol.

Card games were something I thought about that are a logical progression from this, but actually they are more tricky with the game logic and you have to keep a larger array of data for each game (52 cards to anything up to something crazy like canasta). That is probably the next step after I have had enough of creating board games. Build more skills in developing game logic and do the card games. Eventually I can use these in creating the games I really want anyway (rpgs lol).

Next target after noughts and crosses to develop skill is ... Battleships. This is a logical progression to the skills developed in noughts and crosses in that we go from a 3x3 array to a 2 x 10x10 arrays. It can be written so that a series of menus control the action and graphics will be fine on the spectrum screen. The input routines can be handled and the game logic is pretty similar to what was used in noughts and crosses.

There is more scope for adding in some ship sinking animations when either player gets hit. This will help develop skills and help polish my handling of various game states/menus.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

For those playing along at home, here is the original MSX basic listing I used as the template for the game.

This is crap game gold, taking a two player game that could have easily been played on scrap paper with better graphics and a more intuitive interface and putting it onto a computer. I love these programs. There is something heroic about the lack of analysis that goes into such a folly. As a testament to that - I took it further and made an assembly language version. :lol:

Anyway you can take a look at the base program. The book its from is full of games like this, so its a real treasure of crap games begging to be given the assembly graphics and sound overhaul.


Image

Image

Image
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Which MSX emulator do you recommend? Ideally one that does MSX2 as well.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Seven.FFF wrote: Thu Jan 25, 2018 2:22 pm Which MSX emulator do you recommend? Ideally one that does MSX2 as well.
openMSX is what I use but I don't really know enough about it to form an opinion there are a bunch of others that you could use.

fmsx is also referenced a lot, but there was a lot of technical documentation with the MSX so the emulation standard seems to be very good. With openMSX you can create your own configurations of MSX machine even ones that did not exist. It handles MSX2 and the MSX2+.

The main thing with openMSX is making sure that you have a manufacturer rom otherwise using the graphics launcher is just a pain because the generic rom does not allow you to use disk images. That sucks as the majority of MSX software is going to be on disk. But its fairly trivial to track down hundreds of manufacturer roms for MSX.

What I did was downloaded openMSX, then catapult (the graphic front end), then went to archive.org and got the TOSEC for MSX and MSX2. Then I realised I needed the manufacturer roms to actually run anything but the cartridges and spent about 30 mins googling. One you have that there are a few books on the net but nothing like the amount that there are for say atari/commodore or spectrum.

But where you loose with the books, you gain with the software - there is a lot available and tons of quality releases.

That said if I was an adult back in the 80s for sure I would have bought MSX, they are so nice to use and it was a common standard so there were lots of peripherals available (especially in Japan). It's a shame they were not more popular in the UK or US. With it being a common standard a lot of the compatibility issues that held up progress with microcomputers would have been avoided.

There are C compilers, Pascal, Forth, Logo, (think there is a Fortran and Cobol version available..). Plus a bunch of assemblers.I have not looked too deeply into it but Zen seems to be ok if you don't mind using a Merlin style program to develop on the platform. I got pasmo to compile roms for MSX. You have hardware sprite support and a bunch of other bios routines that help with making applications, plus openMSX has a nice monitor you can generate stuff like floppy disks on the fly I really only scratched the surface with what it can do.

There are tons of resources if you can read Japanese, there is still more that has never been scanned/loaded up onto the net but its all sat rotting on bookshelves in Japanese thirft stores and book warehouses. I remember seing junk shops when I was over there and they were filled floor the ceiling with crap for the MSX, peripherals, magazines, books, softs. One of the heart breakers was I saw a documentary on MSX over there they were interviewing a programmer and he had the source code listings all printed and in his little office for all these games that has never been preserved or studied. A guys whole store of programs and he didn't think anyone would want to look at it. I'll see if the documentary is on youtube it was pretty good.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Cheers, that sounds good. I'm looking at porting Metal Gear 1 from MSX2, so at some point I really should get round to running it(!). I appreciate the detailed tips :)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

no worries, nothing worse than sitting in front of openMSX and wonder why nothing will load.

Image

That was me the first time I tried to run a game on openMSX lol.

That said its not a good day without one programming rage quit :lol:

Metal gear is a quality game - would be awesome to see how you got that to run on the Spectrum.

My guess is with the MSX once you nail the memory map and figure out how to talk to the rom its all pretty peachy but the tricky part is trying to overcome the limitations of the spectrum. The MSX gives you a lot of support to do great stuff. I think that is why there is some justifiable distaste for a lot of the spectrum titles that got ported to MSX, they didn't take advantage of the MSX hardware support that would make the games run much faster.

But going the other way, haha well the crap basic games are fine but my god trying to get even close to what it could do with some of the professional titles would be outstanding to even get close on the spectrum.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

I had a FUUUUUUUUU- ragequit with openMSX too. Finally got it running with blueMSX, found an English translation patch, and managed to patch it.

I reaaally wanna use C.Born's wav2ay method to have it say "SNAAAAAAAAKE!!!" :D

Haven't got very far with it yet, but it'll be a radastan mode game that'll run on the Uno and ZEsarUX (and maybe the Next with some tweaking). I'm still playing around with a game screen graphics conversion workflow, but I got a title screen going.

Image
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

That looks sweet, its amazing what can be done with the new libraries. I have been itching to getting round to using the NIRVANA libraries but gotta get the basics down first.

Mind was blown today when I finally figured out I could compress more than screens with zx7 :lol: I was like 'if its all data.. then why not level data...' :mrgreen: depending on the compression ratios its making a game the size of dragonquest look at least remotely possible with multiloading of location data using the compression. I had been scratching my head for a while trying to figure out how to squeeze a open world into 30k with everything else up until now.

Helped keep crapchess's size down also, the background screen now weighs in at 320 bytes compressed. Might even have enough space for a continuous music track now.

But sure blueMSX is the one you tend to see in the youtube videos talking about msx. I think openMSX has a bit of a steep learning curve but once stuff starts to work its nice.

As a way to save the sanity of people trying to follow along with the various projects I waffle about here in the showcase I decided it was high time to get on the github bandwagon and put all the crap online for everyone to see the hot garbage that is my projects.

With all the source code your be able to have a chuckle at my potato antics and experience first hand the bizarre bugs and blind alley ways my projects inevitably take. any bug fixes or general sanity checks are most appreciated. It's also a good way to guard against my decrepit laptop finally giving up the ghost and taking all my data with it. Should be all set up by tomorrow.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 26: 339 days left.

UNLIMITED POWER!!! <emperor cackle..>

I dug up a few of my old forth notebooks this morning while cleaning out some boxes. It got me thinking this might help organize and streamline my z80 assembly projects. Library's of subroutines are nice but you loose precision and specificity with this approach and the programs eventually become needlessly cluttered with code you don't require for that particular application.

But nobody has the time to hand craft custom libraries of subroutines for each project. That would take too long.. But if the process were automated.. taking a few details about the target project that would enable a custom file full of optimised subroutines for that particular application. It would be pretty kick ass.

FORTH is a great little language, I forgot just how powerful and at the same time weird it can be. Both high and low level. Part of this is driven by me being lazy and not particularly careful in my coding. I make to many mistakes to be hand coding assembly routines all the time. With a generator handling the low level implementation of my projects that would give me a sanity check that I got the basics right while at the same time freeing me up to concentrate on new challenges.

Being able to write something like ..

Code: Select all

: GAMEINTRO              STUDIO-BANNER  TITLE-SCREEN INTRO-MUSIC ?ANYKEY ;
: STUDIO-BANNER     INCBIN-FILE SENDVRAM PLAY-SFX FADE2BLK ;
: TITLE-SCREEN         INCBIN-FILE SENDVRAM PLAY-SFX FADE2BLK ;
: INTRO-MUSIC           LOAD-PLAYER START-MUSIC ;
: ?ANYKEY                   ." SHAZAM! I AM A STUB * ;

...
Checking out the constants list that FFF seven sent my way got me thinking it would be nice if I could have whole blocks of code like this, how much faster cobbling together the projects would be. So I recalled how easy it was in forth to do this. Now I just need to track down a z80 opcode list and I will be cooking on gas. No need to write a whole assembler, all the forth program will do is spit out complete project skeletons with assembly listings ready to use in pasmo or zeus.

One big advantage to doing things this way is things like ports to separate targets become more possible, as long as there is an equivalent technique to achieve a desired effect its not hard to set that up with forth. That would be sweet.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

The tools rule..

A big issue with my development process is my eyesight is not the best so the small fonts that are used in wine and other tools does not make itself so useful. I can't read the small characters.

There are ways round it like zeus I can increase the size of the text inside the editor but not the menus that are handled by wine. It means that when I use the emulators I am taking the equivalent of a knife to a gunfight when trying to do debugging and traces.

Interestingly enough though I can enlarge the fonts on native applications so stuff like sublime editor I can have the fonts all quite large. So at least the text editor works.

This is just a rant, but - why on earth would people write applications with tiny fonts in the first place? It's hard enough to use these tools anyway without making the interface look like a eye test. :lol: (to put this into perspective, my font on sublime is 20.. yes I have bad eyesight lol..)

But enough of my moans, good things happened today. I got the first version of my forth tool to glue together subroutines into program source. Looking through my notes I forgot just what groovy stuff could be done. memory dumps on the fly, the language turns a modern platform into something you can play with as if it was a microcomputer/microcontroler.

While I can't figure out the cross assembler that comes with it, like I said its not what I am here to do (while writing an assembler for the z80 would be pretty kick ass, its also way beyond what I can do at the moment - plus why re-invent the wheel?).

What I am thinking to do though is because I can just write binary data where-ever and in whatever way I want. This gives me the ability to create my own spectrum file formats from within the application.

The big advantage with this is I can glue together a bunch of different applications and emulators all in the one place to enable testing, editing, building in one place. That will save a ton of time and prevent a bunch of mistakes.

I could have done it with batch files/scripts i guess. But not to the type of integration that I can now do. Having the memory dumps large enough that I can see them is cool. Next thing is to see exactly how much you can manipulate fuse with command arguments/options/config files.
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Crap 0.1 first assembly project

Post by dfzx »

Nomad wrote: Fri Jan 26, 2018 2:20 am But nobody has the time to hand craft custom libraries of subroutines for each project. That would take too long..

...

With a generator handling the low level implementation of my projects...
Aren't you just describing a compiler? You express what you want in a higher level language and the generator turns it into assembly language for you?
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Crap 0.1 first assembly project

Post by Ast A. Moore »

Nomad wrote: Fri Jan 26, 2018 8:21 am A big issue with my development process is my eyesight is not the best so the small fonts that are used in wine and other tools does not make itself so useful. I can't read the small characters.
What platform are you on? Do you have to use Wine?
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

dfzx wrote: Fri Jan 26, 2018 8:22 am
Nomad wrote: Fri Jan 26, 2018 2:20 am But nobody has the time to hand craft custom libraries of subroutines for each project. That would take too long..

...

With a generator handling the low level implementation of my projects...
Aren't you just describing a compiler? You express what you want in a higher level language and the generator turns it into assembly language for you?
In a limited way, its not producing machine code though. That said there was no reason why it couldn't do that in the future.
Ast A. Moore wrote: Fri Jan 26, 2018 8:39 am What platform are you on? Do you have to use Wine?
I use arch linux, at the moment I am using a rather old laptop, there is no way it can run windows (well beyond xp I guess.) When I get a new machine I will have it as a dual boot so I can use the windows specific stuff that way. But until then I am stuck with wine. :lol:
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Crap 0.1 first assembly project

Post by dfzx »

Nomad wrote: Fri Jan 26, 2018 9:13 am When I get a new machine I will have it as a dual boot so I can use the windows specific stuff that way. But until then I am stuck with wine. :lol:
No need to dual boot. Create a Winders image in VirtualBox. Any modern machine can run a virtual machine these days, and integration is quite nicely handled with modern software so you can copy and paste, save to the Linux file system, etc.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Progress was pretty steady today, nothing spectacular but further forward than before so that is ok. I thought I would have been done with the noughts and crosses today but ended up spending more time than I should have playing with zx7 and coding the new tools in forth. :lol: Still progress is at a good place with the noughts and crosses so I am not particularly worried.

Seems to be too much text and not enough pretty pictures so...

Image

Now get to use my machine like its 1990 again with a menu list of programs that I regularly use - I hit a key and it launches the program I want. How far we have come lol.

Aside from that I went through the TZX file standard and it seems pretty straight forward, it seems more of a wrapper with meta data for a tap file from what I can see. I have been trying to find the sepctrum standard for the TAP file. Is it the same as the C64? with the 3 different values for long,medium and short tones?

The other standards I have been trying to track down are

spectrum disks - I can't seem to find much info on these. I remember back in the day there was one computer store by the early 90s that had the 3" disks in the south west (Weston Super Mare!) I guess they were never that popular.

The other thing is micro drives, I can't seem to get them to work in fuse. Is there some special configuration I messed up? there are a few magazine disc that were distributed on micro drive that I want to look at but can't. They list as over 700k... if that is true how can I create my own to use to store program data?

What is the simplest file format to generate? What I want to do is be able to write the file on the fly with updated data kinda like pasmo does when it compiles a basic loader with the bin data and the assembly file.

I generated a pasmo file that was just a bare bones project used the tzxbas and had a look at that but the specification seems to be a little out of date on the WOS website.

for the people playing along at home.. here is the skeleton source code for the menu program that I use for the editor and running the applications. You can just add your own applications and obviously change the file names to suit your own projects.

Code: Select all

( MENU SYSTEM - ALL THE PROGRAMS AND TASKS I DO REGULARLY )
( ITS LIKE ITS 1990 AGAIN. )

: EMPTY    s" ---marker--- marker ---marker--- " evaluate ;
: EDIT    s" subl main.fs " system ;
: RUN     s" main.fs " included ;
: ECR     EDIT RUN ;

marker ---marker---
It forms a loop where it constantly drops you back into the forth interpreter so you can run the editor, run the other apps (the system calls are what are used to load the external programs.) This acts like a launcher app for the rest of the system.

Anyway trivial but surprisingly useful.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Here is another useful photo copyable/printable screen planner. It's from a MSX book but its 192x256 pixels so will work just fine for the spectrum.

Image

The issue you might have is that its not 8x8 squares, so unless your doing full screens its probably going to make more sense to use the 8x8 grids or 16x16.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 27: 338 days left.

Still no Noughts and Crosses or CrapChess but - I now have a fully functional application launcher :lol:

Now with a single word access to my projects in the editor, another word to assemble and run in emulator. No more annoying directory locations to remember for the wine applications. Sevenup and Zeus run with one word 8-)

The next step is putting the various spectrum native utility's that I use on the launcher, then the sound effects programs and the trackers will run from one word each from the launcher.

The next thing to do is go through all the various applications I have on the system now and put them into the launcher and probably create a little menu listing so I can remember the commands.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Well today was productive. Like I said earlier I got the application launcher working how I wanted. No more searching for where I placed the programs or remembering command line incantations to get the things to work.

What this also gives is the chance to bring together a lot of utility programs that I had previously downloaded and completely forgotten about. Stuff like spectrum clipart and fonts. All that stuff is now together and ready to be used. All of the great little music utilities all ready to go.

The other big news is I can now import text bas files into tap with the great zmakebas from Derek Bolli. This makes things so much easier than having to wrestle with typing in fuse.
:D

All these utilities and streamlining of work flow make work on the actual projects so much easier.
Post Reply