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: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Works for me Jason, but it does need a proc/endp inside the rept/endm, despite what the doumentation says. It that respect it works the same way as Zeus.

Code: Select all

org 32768

Test:
	rept 4
          proc
_A:  
	    jp _A
          endp
        endm
 	ret

end 32768

Code: Select all

C:\Users\robin\Documents\Visual Studio 2015\Projects\ZalaXa\src>pasmo --tapbas --alocal test.asm test.tap test.txt

C:\Users\robin\Documents\Visual Studio 2015\Projects\ZalaXa\src>

Code: Select all

00000000	EQU 08000H
00000001	EQU 08003H
00000002	EQU 08006H
00000003	EQU 08009H
Test		EQU 08000H
Without --alocal, fail:

Code: Select all

C:\Users\robin\Documents\Visual Studio 2015\Projects\ZalaXa\src>pasmo --tapbas test.asm test.tap test.txt
ERROR on line 6 of file test.asm
ERROR: Invalid definition, previously defined as EQU or label
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 »

Day 12: 353 days left..

With the anykey subroutine doing a good job of not crashing the program. It was time to get a little more precise/discerning with the keyboard input. Debugging the fallout from the following code will probably take up a lot of the project time today. But without it there is no real interaction beyond anykey on the menus (and later the main game). So it pays to get this right as soon as possible.

The code is from Chuntey blog. https://chuntey.wordpress.com/2012/12/1 ... chapter-2/ I adapted it to call the various menus instead of up,down.left,right. Now me at 3am in the morning probably was more potato than me fully refreshed so lets hope I can see the obvious errors that were hanging the program and making it unresponsive.

First the code.

this is the main.asm for crapchess

Code: Select all

org 50000

include "changebordercolour.asm"
include "changeinkpaper.asm"
include "mainmenu.asm"
include "keyboard.asm"
include "clearscreen.asm"
include "splashscreen.asm"
include "soundfx.asm"
include "random.asm"

Main:
	call randomChuntey
	and 7
	call rndSoundFXGen
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call splashScreen
	call keyboardAnyKPress
	call wiggy
	call blp1
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call mainMenuScreen
	; call keyboardAnyKPress
	call wiggy
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call gameMenuScreen
	call keyboardAnyKPress
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call aboutMenuScreen
	call keyboardAnyKPress
	call wiggy
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call soundMenuScreen
	call keyboardAnyKPress
	call wiggy
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call controlsMenuScreen
	call keyboardAnyKPress
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call helpMenuScreen
	call keyboardAnyKPress
	call wiggy
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call randomChuntey
	and 255
	call changeInkPaper
	call clearScreenRom
	call attractScreen
	call keyboardAnyKPress
	call wiggy
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call clearScreenRom
	call quitMenuScreen
	call keyboardAnyKPress
	call rndSoundFXGen
	call randomChuntey
	and 7
	call changeBorderColour
	call clearScreenRom
	call highScoreMenu	
	ld (51000),a
	jp Main
	ret
end Main
this is the mainmenu.asm - where the information about the main menu screen lives

Code: Select all

include "test.asm"
include "helpmenu.asm"
include "controlsmenu.asm"
include "gamemenu.asm"
include "soundmenu.asm"
include "aboutmenu.asm"
include "quitmenu.asm"
include "highscoremenu.asm"
	
mainMenuScreen:
	ld a, 2
	call 5633
	ld de, mainMenuString
	ld bc, eostr2-mainMenuString
	call 8252
	call keyboardTest1234
	ret

mainMenuString: defb 22,2,8,"Main Menu screen."
		defb 13,"1:MENU 1"
		defb 13,"2:MENU 2"
		defb 13,"3:MENU 3"
		defb 13,"4:MENU 4"
		defb 13,"5:MENU 5"
		defb 13,"6:MENU 6"
		defb 13,"7:MENU 7"
eostr2: equ $
this is the keyboard.asm file. Where all the keyboard input subroutines live.
as a sanity check I did a direct copy paste from the blog, and just replace the subroutine jumps to my program menus. (keyboardTest1234)..

Code: Select all

keyboardAnyKPress:
		ld hl,23560     ; 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.

keyboardTest1234:
       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,aboutMenuScreen         ; it's being pressed, move left.
       pop af              ; restore accumulator.
       rra                 ; next bit along (value 2) = key 2.
       push af             ; remember the value.
       call nc,gameMenuScreen         ; being pressed, so move right.
       pop af              ; restore accumulator.
       rra                 ; next bit (value 4) = key 3.
       push af             ; remember the value.
       call nc,soundMenuScreen         ; being pressed, so move down.
       pop af              ; restore accumulator.
       rra                 ; next bit (value 8) reads key 4.
       call nc,controlsMenuScreen         ; it's being pressed, move up.
       ret
       
		
keyboardTest12345:
	ld bc,63486	; keyboard row 1-5/joystick p2
	in a,(c)	; see what keys are pressed
	rra		; outermost bit = key 1
	push af		; remember the value
	call nc,aboutMenuScreen	; its being pressed - load about menu
	pop af		; restore accumulator
	rra		; next bit along (value2) = key 2
	push af		; remember the value
	call nc,gameMenuScreen 	; its being pressed - load game menu
	pop af		; restore accumulator
	rra		; next bit along (value4) = key 3
	push af		; remember the value
	call nc,soundMenuScreen	; its being pressed - load sound menu
	pop af		; restore accumulator
	rra		; next bit along (value8) = key 4
	push af		; remember the value
	call nc,controlsMenuScreen ; its being pressed - load control main
	pop af		; restore accumulator
	rra		; next bit along (value16) = key 5
	push af		; remember the value
	call nc,helpMenuScreen ; its being pressed - load help menu
	ret

when keyboardTest12345 is called none of the keys respond...

have the menu screen set a memory location to hold the subroutines in order like.

CHOICE1, CHOICE2, CHOICE3, CHOICE4, CHOICE5

then calls the keyboard input subroutine,

the subroutine looks at memory location X, then if key 1 is pressed, call subroutine from memory location[1]

the subroutine looks at memory location X, then if key 2 is pressed, call subroutine from memory location[2]

the subroutine looks at memory location X, then if key 3 is pressed, call subroutine from memory location[3]

the subroutine looks at memory location X, then if key 4 is pressed, call subroutine from memory location[4]

the subroutine looks at memory location X, then if key 5 is pressed, call subroutine from memory location[5]

That way I could have menu key input as a subroutine, and just pass the subroutines for the calls to the memory location for each menu page. Making things a lot more tidy if you see what I mean.

I think these would be described as 'jump tables'

Another weird issue I have been having is trying to get fuse to load the outlet microdrives from the archive. There are some nice programs contained in this magazine but most of the issues are distributed as microdrive only. is there a way I can load these into fuse?

A fair question is ... why bother searching the archives for 'skillz', well using my potato logic mostly derived from Dragonlance novels: I equate the archive to being a similar situation with finding the ancient tombs + Fistandantilus spell books. But saying 'nah bro.. who needs that..' :lol:

Just browsing I notice there are routines for screen wipes, scrolls and other interesting effects that would make my projects look better. my plan was to scour the archive for every useful assembly routine/technique and compile them into a wiki. If the 'skills' were arranged in modular form it would be pretty useful and furthermore could only help me learn.

The plan was to go from this..
Image
to this...
Image

with Assembly gains :lol:
Any tips to good assembly routines in the archives would be appreciated.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

As an addition to todays progress report, now the project code is starting to get quite large, and having multiple source files. Even with lots of comments and my wibble in this development log even I am starting to find it difficult to keep track of what such and such subroutine does in the program and how it fits into the overall picture.

I think the best idea is to use a diagram tool to make it more visual, Dia is pretty good for this. And anyone that did a computer science course last century will be well acquainted with flowcharts. :lol:

So to help documentation - and for future reuse this is essential for comprehension and quickly understanding if the code cam be used or not in new projects. Each subroutine is going to get its own flow chart detailing its intended use, what it calls, what it writes, what it reads, code execution.

It might slow me down a bit going back through the code but I think its going to pay dividends later on. Especially as I want to reuse as much of the code as possible in future projects.

kinda like this..

Image
User avatar
Joefish
Rick Dangerous
Posts: 2042
Joined: Tue Nov 14, 2017 10:26 am

Re: Crap 0.1 first assembly project

Post by Joefish »

Seven.FFF wrote: Thu Jan 11, 2018 11:18 pm Works for me Jason, but it does need a proc/endp inside the rept/endm, despite what the doumentation says. It that respect it works the same way as Zeus.
I was referring to the LOCAL directive, not the auto local mode.
I've still not seen any way of making it work in context.
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 12, 2018 7:59 am As an addition to todays progress report, now the project code is starting to get quite large, and having multiple source files. Even with lots of comments and my wibble in this development log even I am starting to find it difficult to keep track of what such and such subroutine does in the program and how it fits into the overall picture.
To each his own, but I’ve never been partial to multi-source projects. All of mine are single-source (aside from inserting large data files such as fonts, some graphics, etc.). The only place I tend to combine multiple sources is the loader. If you use comments correctly, and your text editor has good search options, I find it much easier to keep track of things when everything is in a single file.

Versioning also becomes much easier.

Your milage may vary, obviously.
Last edited by Ast A. Moore on Fri Jan 12, 2018 10:38 am, edited 1 time in total.
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 »

Ast A. Moore wrote: Fri Jan 12, 2018 9:26 am To each his own, but I’ve never been partial to multi-source projects. All of mine are single-source (aside from inserting large data files such as fonts, some graphics, etc.). The only place I tend to combine multiple sources is the loader. If you use comments correctly, and your text editor has good search options, I find it much easier to keep track of things when everything is in a single file.

Versioning also becomes much easier.

Your milage may vary, obviously.
It is nice to have everything in its place, but then a part of me thinks "when I had a single file I just used to search the file for the label using the editor.. " lol. I do want to try this approach and give it a spin. If I can get on with it then so much the better. But it was worth trying early I think.

The version control - Yea actually I think it would make more sense for me to start putting the project on github, that way I don't have to keep pasting lots of code examples. Interested people could just download the whole thing and take a look. Would then be able to study revision histories as you say. But all of this is on another level of organisation than I am currently used to.

I have completed the flow diagram for the multikey input subroutine (the one from the Chuntey blog that I butchered.)

Image

Now I look at the diagram, its not quite correct because it does not show the expected inputs to the subroutine or the subroutine start point, plus if I was to be a real stickler it should have input as an external process to the subroutine lol... plus really I should have annotated the diagram much more. Ah well can always go back when the thing is actually working and make it beautiful.

Here is the press any key subroutine...

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

Re: Crap 0.1 first assembly project

Post by Nomad »

Joefish wrote: Fri Jan 12, 2018 9:05 am I was referring to the LOCAL directive, not the auto local mode.
I've still not seen any way of making it work in context.
I never managed to get the LOCAL directive to work either, I spent around 30 mins trying all the variations I could think off and nothing worked - at the time I put it down to me being a potato and just moved on.. But now I suspect that it was a unimplemented feature that got addressed on the down low by using the --alocal. But that is just a conspiracy theory :lol:

Project news: well I got paranoid about my flowchart recollections. So decided to see if there was a standard. There is but even better .. Big blues very own guide! and its only 40 pages. So I went with the IBM book. http://web.eah-jena.de/~kleine/history/ ... 8152-1.pdf Will have a read through and make sure my flowcharts are up to scratch.

All joking aside having the subroutines documented in this way is really nice way to get things straight in my head. It's not the fastest way to go but I think its the most comprehensive way to document what I am doing. Put in some effort now when I write (or shamelessly copy paste) a subroutine and it will help spot bugs, and be useful for next time. Also exposes the gaping holes in my understanding of what's going on with the sound generator subroutine that I pilfered from SoundFX. (what are the other 2 values doing... hmmm). That is high on the list of subroutines to flowchart. But I need to figure out what's actually happening first :lol:

So this is the print number subroutine,Chuntey's blog once again. This subroutine is just a call to the rom print line number routine. I plan to use it in creating a clone of SoundFX but with less features... :lol:

Image
Last edited by Nomad on Fri Jan 12, 2018 4:38 pm, edited 1 time in total.
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Joefish wrote: Fri Jan 12, 2018 9:05 am I was referring to the LOCAL directive, not the auto local mode.
I've still not seen any way of making it work in context.
Still needs proc/endp nested inside rept/endm. You can see in the source, parsePROC and parseMACRO push a new "his ambit" (lol) onto the local stack, whereas parseREPT doesn't. Wouldn't be hard to mod it.

Code: Select all

; local.asm

org 32768

L1
		jp L1

Main		PROC 
		LOCAL L1
L1
		jp L1
		ENDP

		REPT 4		
		PROC
		LOCAL L2
L2
 		jp L2
		ENDP
		ENDM

MyMacro		MACRO
		LOCAL L1
L1
		jp L1
		ENDM

		MyMacro()
		MyMacro()
		
end 32768

Code: Select all

C:\Users\robin\Documents\Visual Studio 2015\Projects\pasmo\examples>pasmo local.asm local.bin local.txt

C:\Users\robin\Documents\Visual Studio 2015\Projects\pasmo\examples>

Code: Select all

00000000	EQU 08003H
00000001	EQU 08006H
00000002	EQU 08009H
00000003	EQU 0800CH
00000004	EQU 0800FH
00000005	EQU 08012H
00000006	EQU 08015H
L1		EQU 08000H
Main		EQU 08003H
Image

Can coexist wth --alocal option, same results:

Code: Select all

C:\Users\robin\Documents\Visual Studio 2015\Projects\pasmo\examples>pasmo --alocal local.asm local.bin local.txt

C:\Users\robin\Documents\Visual Studio 2015\Projects\pasmo\examples>
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

0.6-pre behaves the same, although that was an extensive rewrite.
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 »

Day 13: 352 days left..

Today being the 13th day of the project, I figured it was better not to work on code so much and instead streamline the documentation/reference process. :lol: my programs go wrong enough without tempting fate.

So project time today will be spent creating flowcharts for all the subroutines so far. To better manage all of the documents I have used tiddlywiki. Its nice I can now search for my subroutines, notes, links to the flowcharts, instruction set reference, memory map.

Before I would just have the rom disassembly book open but this is easier. For code snippets it helps rationalize the process, in the past I just had piles of yellow legal pad paper strewn about willy nilly.

Progress wise, looked into the Rom routine 2D2B a.k.a STACK-BC. Ok I think I understand this routine.

However... the next routine on the list to look at today was 2DE3 a.k.a PRINT A FLOATING POINT NUMBER.
[youtube]https://youtu.be/aNUr__-VZeQ[/youtube]

Aside from the rom routines, looked at the rest of the memory map for the spectrum.

And that was today! Once I have the instruction set, the memory map, and the rom routines in the wiki its going to make work on the project a whole lot easier. having all of the subroutines I use in the programs documented will also help.

I think its not so important for higher level languages unless its a major undertaking but for the assembly unless everything is clearly laid out and recorded its just asking for pain later. How guys could just keep all that information about the instruction set, the memory map and the routines all in their heads is crazy. :lol:
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Crap 0.1 first assembly project

Post by RMartins »

Joefish wrote: Thu Jan 11, 2018 2:11 pm ...
If I've got a bit of code I want to repeat between REPT / ENDM markers, and I put a label in it, it throws up an error as the label counts as a redefinition the second time it's repeated. But every way I can think of for trying to define the label as local to the REPT macro fails.
I believe this is where the problem lays.

You are confusing two concepts, understandbly, because they seem similar, but they are not.

One is a local LABEL, that is limited to the context where it is inserted within.
This is were you use the LOCAL or "_" prefix situations

Another is how to generate DISTINCT labels when using a MACRO.
Here, what you need is to understand how a MACRO works and what the ## operator is for.

A MACRO is just a way to inform the compiler to make Copy&Paste actions (with some optional replace in between), for you.

The manual refers in the Macros Generalities section, the following
Identifier pasting: inside a MACRO the operator ## can be used to join two idenfiers resulting in another identifier. This is intended to allow the creation of identifiers dependent of macro arguments.
This should help you to generate unique and distinct labels when using MACROS.

NOTE: you can also use LOCALs on MACROS, if done correctly.
REPT is just a special MACRO. Check the manual.

WARNING: There is a CAVEAT, when using MACROS, basically a MACRO is referenced by it's name, which can be confused by the compiler to be a label, if you have not included the MACRO before using it.
So take that into account.
User avatar
Joefish
Rick Dangerous
Posts: 2042
Joined: Tue Nov 14, 2017 10:26 am

Re: Crap 0.1 first assembly project

Post by Joefish »

I'm not confusing any of that - I can concatenate names and labels just fine.
What the manual lacks is the syntax for how to use the LOCAL command.

What it seems you need to do is declare your label as local by inserting "LOCAL my_label" on a line within the loop/macro/whatever context, but completely separately from the line where you actually implement the label, e.g "my_label PUSH AF" at the start of your loop or whatever.
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

Yep, exactly. That’s how the parser is coded, for whatever reason.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Crap 0.1 first assembly project

Post by RMartins »

Joefish wrote: Mon Jan 15, 2018 2:17 pm I'm not confusing any of that - I can concatenate names and labels just fine.
What the manual lacks is the syntax for how to use the LOCAL command.

What it seems you need to do is declare your label as local by inserting "LOCAL my_label" on a line within the loop/macro/whatever context, but completely separately from the line where you actually implement the label, e.g "my_label PUSH AF" at the start of your loop or whatever.
OK, but if you can concatenate names and labels, you can create unique labels everytime you call a MACRO, and this prevents the need for LOCAL labels.

We only need LOCAL labels, if somehow we want to use the EXACT same label elsewhere, in a different context.
Because that is the only use case for LOCAL labels.

And if you start to use MACROS that call MACROS you can get into trouble again easily, with either duplicated definitions or unknown labels, when inside a MACRO within another MACRO.

I usualy favor global Labels, parameterized (PREFIX or POSTFIX) to be unique.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 24: 341 days left..

Bet ya thought I had abandoned the project :P No, just my internet connection hates me. In the intervening 11 days went about things old school hitting the books while I was unable to access
the 'world wide web'.

It's surprising what a push that gave things actually, I got all of the graphics finished for crap chess, re-factored the code, created an animated intro screen and played around with a tech demo for copying board layouts from memory. (that was for something completely different but then it struck me this was exactly what I needed for crapchess and controlling the screen!)

Well despite this progress things have been slow, with a combination of no internet and the cat sabotaging my laptop any chance he gets. Its at times like these it shows just how dependent we all have become on the net for a research tool. There were tons of times I was catching myself trying to go onto google to solve a pickle I was in.

In the end I just had to hit the books (usually pointless for specifics) or just brute force a solution by trying every variation of a routine I could to try and get it to work. That is how the board copier 'spawned'. The code is not the prettiest, having used all of the registers already and not really understanding enough to get me out of trouble and the books giving woolly ivory tower explanations like 'manage your stack' :lol: I just used memory locations to store variables.

It was at this point I discovered what was worst than spaghetti goto code... tons of magic numbers for memory locations with values sprinkled willy nilly. Somehow it worked. but I shudder thinking about it...

Music was something that brought a little sanity into the mix. I composed a few little ditties on beepola but the issue was first getting it to load in the program. For very short music its ok. But when things got long or complicated the size of the file was ballooning to 12-15k. When I tried to add it to crap chess I suspect there is not enough room.

I can get the simple tracks to play continuously at the start of the program, but trying the NEXTNOTE code my potato brain seems to not be able to get it to work right.

For crapchess I want to get the background ditty down to a more manageable level so I can have it playing in the background during the game. But I guess its not the end of the world if there is no music.

Image

The other way around this is to radically redactor the code, take out my potato beginners memory mistakes and get the space i need that way.. I am getting to the point where I did everything I can by myself. A little bit of polish I think I can learn a lot from seeing how someone would fix my mess of a program :lol:

A big part of the problem is routines that I have just copy pasta'ed into the project that I don't really understand that use/affect registers. This stops basic stuff like DJNZ working as expected and making me having to resort to non-loopy methods to get things to work. If I could figure out how to preserve the registers, do my loops and replace them I could go on a re-factoring rampage :lol:

Still while its been frustrating and many times I felt like I was making little progress, at the end of the 11 days I am much further along than when I started. The dragon warrior tile loader was something I couldn't have done at the start of this project. I think its the first time I really sat down and thought 'ooh I did that, damn' :roll:

Whole reason behind the tech demo was I was getting cheesed off looking at the same damn green and white board and ugly chessmen every day. Needed something new to fire my braincells. So I figured why not do a tile loader for one of my fav games, dragon quest.

As a project its totally beyond my ability to code, but for stuff like proof of concept and tech demos to teach myself its ok. One day I will make it. :mrgreen:

OUTCOMES:

All sprites are done and in the bag, have a number of new routines to handle screen stuff like timers, player indicator, the animated screens, some music. And of course loading the tiles from a list of values in a memory location that can be updated in real time.

Other things that got completed - pause functions, these were used in the animation sequence for the start screen. I wanted to avoid fitting in the viewers so needed to slow down the rate that the attribute data was switched. Sadly this took almost a day of fiddling to get right, all the time I was cursing my internet thinking how easy it would have been to have gotten a solution with google. Still watching the little animation wiggle on the screen was satisfaction at the end of the day.

The animation is just two attribute pages, I got the idea from a spectrum book - that in turn was exposing a 'trade secret' from 1984 :lol: I thought 'ooh 768x2 bytes' that sure beats 12.2k.. I want some of that action.

That was a great learning tool. Its a very simple technique but looks nice. I am no artist anyway so attribute blocks are more my speed.

Still to do..

I need to figure out what is going on with the input routine, it must be some problem with the way the project is set up but I can't get the multi input routines to work in the program from how to write spectrum games. As a sanity check I wrote out the example game that the code was used in and it works ok. So it must be my project and not a book that has been used by thousands of people to code spectrum games :lol: (but at 3am when nothing is working, these dark thoughts enter the mind none-the-less..)

Will implement the routine from the dragon quest tile loader into crap-chess. It should be easier as its only 8x8 locations compared to 16x12.. (famous last words).


Image

Image

Image

Image

Image

Image

Image

Image

Image

One thing I wanted to master was how to have menus appear on the screen. I have achieved this in a simplistic potato way, but I need to learn masking so the ugly edges can be hidden and it blends better into the scene. At the moment I am just replacing the tiles with blanks. But that is not an elegent solution I think. And still suffering from a lack of loops in my life.

the code for the tech demo is bellow, you can see its hot mess of non-optimised stuff. I would like to learn how to make it better and more efficient. Figure out how to really master this looping business and taking care of my registers instead of praying that I don't negatively impact the rest of the program every time I make a change haha.

I have been trying to get the graphic tile printer (ROLF) to also adjust the attribute memory at the same time but not been having any luck. I remember one of the spectrum books had a routine to determine the attr location of any point on screen so It would be a matter of trying to get the attr from the tile printing function..

Code: Select all

ORG 33000
    
MAIN:
 
    ; SETS MEMORY LOCATION 50000 TO 0 AND 50001 TO 0, USED IN PRINT TILE. B C

    LD A,1
    LD (60000),A
    LD A,120
    LD (23693),A
    CALL 3503
    LD A,0
    CALL 8859

GAMELOOP:
    LD A,0
    LD HL,40000
    LD (HL),0
    INC HL
    LD (HL),0
    INC HL
    LD (HL),32000
    CALL SETMAP
    ;CALL MENUS
    CALL DRAWMAP
    JP GAMELOOP

MENUS:
; 20 IS LEFT TOP CORNER, 21 IS RIGHT TOP CORNER
; 22 IS LEFT BOTTOM CORNER, 23 IS RIGHT BOTTOM CORNER
; 24 IS VERTICAL, 25 HORIZONTAL
        LD A,25
        LD (32017),A
        LD A,25
        LD (32018),A
        LD A,25
        LD (32019),A
        LD A,25
        LD (32020),A
        LD A,21
        LD (32021),A        
        LD A,20
        LD (32016),A
        LD A,24
        LD (32032),A
        LD A,26
        LD (32033),A
        LD A,26
        LD (32034),A
        LD A,26
        LD (32035),A
        LD A,26
        LD (32036),A
        LD A,24
        LD (32048),A
        LD A,26
        LD (32049),A
        LD A,26
        LD (32050),A
        LD A,26
        LD (32051),A
        LD A,26
        LD (32052),A
        LD A,24
        LD (32064),A
        LD A,26
        LD (32065),A
        LD A,26
        LD (32066),A
        LD A,26
        LD (32067),A
        LD A,26
        LD (32068),A
        LD A,24
        LD (32080),A
        LD A,26
        LD (32081),A
        LD A,26
        LD (32082),A
        LD A,26
        LD (32083),A
        LD A,26
        LD (32084),A
        LD A,24
        LD (32096),A
        LD A,26
        LD (32097),A
        LD A,26
        LD (32098),A
        LD A,26
        LD (32099),A
        LD A,26
        LD (32100),A
        LD A,22
        LD (32112),A
        LD A,25
        LD (32113),A
        LD A,25
        LD (32114),A
        LD A,25
        LD (32115),A
        LD A,25
        LD (32116),A
        LD A,23
        LD (32117),A
        LD A,24
        LD (32101),A
        LD A,24
        LD (32085),A
        LD A,24
        LD (32069),A
        LD A,24
        LD (32053),A
        LD A,24
        LD (32037),A
        LD A,21
        LD (32021),A
        RET

DRAWTILE:   ;ARRIVE HL POINTING AT TILE GRAPHIC, DE AT SCREEN MEMORY
    LD B,16     ;LOOP COUNTER FOR 16 PX HIGH TILE
DRAWTILELOOP:
    LD A,(HL)   ;GET BYTE OF GRAPHIC
    LD (DE),A   ;PLONK IT IN SCREEN MEMORY
    INC HL      ;NEXT BYTE OF GRAPHIC
    INC E       ;NEXT COLUMN OF SCREEN
    LD A,(HL)   ;RIGHT HAND SIDE OF TILE
    LD (DE),A
    INC HL      ;NEXT BYTE OF GRAPHIC
    DEC E       ;BACK TO LEFT HAND SIDE OF TILE
    CALL NEXTLINEDOWN   ;MOVE DE DOWN ONE SCREEN LINE
    DJNZ DRAWTILELOOP
    RET
    ;
NEXTLINEDOWN:   ;ARRIVE DE AT SCREEN ADDRESS, MOVE IT DOWN ONE PIXEL LINE
    INC D
    LD A,D
    AND 7
    RET NZ
    LD A,E
    ADD A,32
    LD E,A
    RET C
    LD A,D
    SUB 8
    LD D,A
    RET

YX2CELL:    ;arrive with b=y column 0-23, c=x column 0-31, point DE at corresponding screen address
    LD A,B
    RRCA
    RRCA
    RRCA
    AND 224
    OR C
    LD E,A
    LD A,B
    AND 24
    OR 64
    LD D,A
    RET

FOREST:
        CALL YX2CELL
        LD HL,TILE_FORREST
        CALL DRAWTILE
        RET

SEA:
        CALL YX2CELL
        LD HL,TILE_SEA
        CALL DRAWTILE
        RET

GRASS:
        CALL YX2CELL
        LD HL,TILE_GRASS
        CALL DRAWTILE
        RET

VLINE:
        CALL YX2CELL
        LD HL,TILE_VLINE
        CALL DRAWTILE
        RET

HLINE:
        CALL YX2CELL
        LD HL,TILE_HLINE
        CALL DRAWTILE
        RET

TLCOR:
        CALL YX2CELL
        LD HL,TILE_TLCOR
        CALL DRAWTILE
        RET

TRCOR:
        CALL YX2CELL
        LD HL,TILE_TRCOR
        CALL DRAWTILE
        RET

BLCOR:
        CALL YX2CELL
        LD HL,TILE_BLCOR
        CALL DRAWTILE
        RET

BRCOR:
        CALL YX2CELL
        LD HL,TILE_BRCOR
        CALL DRAWTILE
        RET

WALL:
        CALL YX2CELL
        LD HL,TILE_WALL
        CALL DRAWTILE
        RET

BRICKFLOOR:
        CALL YX2CELL
        LD HL,TILE_FLOOR
        CALL DRAWTILE
        RET

STAIRSU:
        CALL YX2CELL
        LD HL,TILE_STAIRSU
        CALL DRAWTILE
        RET    

STAIRSD:
        CALL YX2CELL
        LD HL,TILE_STAIRSD
        CALL DRAWTILE
        RET    


TABLE:
        CALL YX2CELL
        LD HL,TILE_TABLE
        CALL DRAWTILE
        RET

DOOR:
        CALL YX2CELL
        LD HL,TILE_DOOR
        CALL DRAWTILE
        RET

MOUNTAIN:
        CALL YX2CELL
        LD HL,TILE_MOUNTAIN
        CALL DRAWTILE
        RET
HILLS:
        CALL YX2CELL
        LD HL,TILE_HILLS
        CALL DRAWTILE
        RET
STRIPES:
        CALL YX2CELL
        LD HL,TILE_STRIPES
        CALL DRAWTILE
        RET

SWAMP:
        CALL YX2CELL
        LD HL,TILE_SWAMP
        CALL DRAWTILE
        RET

CHEST:
        CALL YX2CELL
        LD HL,TILE_CHEST
        CALL DRAWTILE
        RET

INN:
        CALL YX2CELL
        LD HL,TILE_INN
        CALL DRAWTILE
        RET   

ARMOURER:
        CALL YX2CELL
        LD HL,TILE_ARMOURER
        CALL DRAWTILE
        RET

OLDMAN:
        CALL YX2CELL
        LD HL,TILE_OLDMAN
        CALL DRAWTILE
        RET   

GUARD:
        CALL YX2CELL
        LD HL,TILE_GUARD
        CALL DRAWTILE
        RET

KING:
        CALL YX2CELL
        LD HL,TILE_KING
        CALL DRAWTILE
        RET

TOWNSPEOPLE:
        CALL YX2CELL
        LD HL,TILE_TOWNSPEOPLE
        CALL DRAWTILE
        RET

TBLANK:
        CALL YX2CELL
        LD HL,TILE_BLANK
        CALL DRAWTILE
        RET   

PLAYER:
        CALL YX2CELL
        LD HL,TILE_PLAYER
        CALL DRAWTILE
        RET   



SETMAP:              ; sets the main screen background
       LD BC,192             ; length of block to copy
       LD HL,ROOM_TANTEGEL_1_2           ; source address
       LD DE,32000             ; destination address
       LDIR                    ; copy BC bytes from HL to DE

       RET

ROLF:

       CP 0
       JP Z,BRICKFLOOR
       CP 1
       JP Z,WALL
       CP 2
       JP Z,STAIRSU
       CP 3
       JP Z,GRASS
       CP 4
       JP Z,SEA
       CP 5
       JP Z,FOREST
       CP 6
       JP Z,TABLE
       CP 7
       JP Z,DOOR
       CP 8
       JP Z,STAIRSD
       CP 9
       JP Z,MOUNTAIN
       CP 10
       JP Z,HILLS
       CP 11
       JP Z,STRIPES
       CP 12
       JP Z,SWAMP
       CP 13
       JP Z,INN
       CP 14
       JP Z,OLDMAN
       CP 15
       JP Z,GUARD
       CP 16
       JP Z,KING
       CP 17
       JP Z,TOWNSPEOPLE 
       CP 18
       JP Z,CHEST
       CP 19
       JP Z,ARMOURER
       CP 20
       JP Z,TLCOR
       CP 21
       JP Z,TRCOR
       CP 22
       JP Z,BLCOR
       CP 23
       JP Z,BRCOR
       CP 24
       JP Z,VLINE
       CP 25
       JP Z,HLINE
       CP 26
       JP Z,TBLANK
       CP 99
       JP Z,PLAYER
       RET                     ; return

ROO16:
        LD IX,16
NMFR:
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        CALL ROO
        DEC (IX)
        LD e,(IX)
        CP 0
        JP Z,NMFR
        RET

DRAWMAP:

        LD IY,32000
        LD A,0
        LD (50000),A
        LD A,0
        LD (50002),A

        CALL ROO16

        LD A,2
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16
 
        LD A,4
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16
 
        LD A,6
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16
 
        LD A,8
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16
 
        LD A,10
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,12
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,14
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,16
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,18
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,20
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16

        LD A,22
        LD (50000),A
        LD A,0
        LD (50002),A
        CALL ROO16
        RET

ROO:
        LD A,(50000)
        LD B,A
        LD (50000),A
        LD A,(50002)
        LD C,A
        ADD A,2
        LD (50002),A
        LD A,(IY)
        CALL ROLF 
        INC IY                   
        RET

;Tantegel castle Top left. (1 of 6)

ROOM_TANTEGEL_2_1:
    DEFB    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    DEFB    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    DEFB    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    DEFB    1,1,1,1,0,0,0,0,0,18,0,0,1,1,1,1
    DEFB    1,1,1,1,0,6,6,6,6,6,6,0,1,1,1,1
    DEFB    1,1,1,1,0,6,16,6,6,0,6,0,1,1,1,1
    DEFB    1,1,1,1,0,0,0,18,18,0,0,0,1,1,1,1
    DEFB    1,1,1,1,0,0,0,0,0,0,0,15,1,1,1,1
    DEFB    1,1,1,1,0,0,15,0,15,0,0,0,1,1,1,1
    DEFB    1,1,1,1,1,1,1,7,1,1,1,1,1,1,1,1
    DEFB    1,1,1,1,0,0,0,0,0,0,0,8,1,1,1,1
    DEFB    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
ROOM_TANTEGEL_1_1:
    DEFB    3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
    DEFB    3,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3
    DEFB    3,1,0,0,0,0,0,1,3,5,3,5,5,3,5,3
    DEFB    3,1,0,0,0,0,0,1,3,3,3,3,3,3,3,3
    DEFB    3,1,0,0,1,0,0,1,1,1,1,0,0,1,1,1
    DEFB    3,1,0,0,0,0,0,15,0,0,0,0,0,0,0,0
    DEFB    3,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1
    DEFB    3,1,1,1,1,1,0,1,15,0,0,0,0,0,0,0
    DEFB    3,1,0,0,0,1,0,1,2,0,0,0,0,0,1,0
    DEFB    3,1,0,17,0,0,0,1,15,0,0,0,0,0,0,0
    DEFB    3,1,0,0,0,1,0,1,1,1,0,0,0,0,1,1
    DEFB    3,1,1,1,1,1,0,1,5,5,0,0,0,0,5,5

ROOM_TANTEGEL_1_2:
    DEFB    3,1,0,0,0,1,0,1,5,5,0,0,0,0,5,5
    DEFB    3,1,0,0,15,1,0,1,5,3,0,0,0,0,3,5
    DEFB    3,1,18,0,0,7,17,1,3,3,0,0,0,0,3,3
    DEFB    3,1,0,18,0,1,0,1,3,3,0,0,0,0,3,3
    DEFB    3,1,18,0,18,1,0,1,3,0,0,0,0,0,0,3
    DEFB    3,1,1,1,1,1,0,1,3,0,4,4,4,4,0,3
    DEFB    3,1,0,0,0,0,0,0,0,0,4,11,11,4,0,0
    DEFB    3,1,0,0,0,0,0,0,0,0,4,11,11,4,0,0
    DEFB    3,1,1,1,0,0,1,1,1,0,4,4,4,4,0,1
    DEFB    3,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1
    DEFB    3,1,0,0,0,0,0,0,1,1,0,0,0,0,1,1
    DEFB    3,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0

TILE_FLOOR:
    DEFB      8,  8,  8,  8,255,255,128,128
    DEFB    128,128,128,128,255,255,  8,  8
    DEFB      8,  8,  8,  8,255,255,128,128
    DEFB    128,128,128,128,255,255,  8,  8
    DEFB     16, 16, 16, 16 

TILE_WALL:
    DEFB    252, 63,200, 19,128,  1,144,  1
    DEFB    224,  1,184,  1,204,  5,166,  3
    DEFB    192,  1,160,  1,176,  1,209, 83
    DEFB    194, 37,230, 17,200, 11,255,255
    DEFB     56, 56, 56, 56

TILE_CHEST:
    DEFB      0,  0,  0,  0,115,156,127,252
    DEFB    241,140,216,198,140, 99,140, 99
    DEFB    255,255,140, 99,141,251,141, 11
    DEFB    141,251,204, 99,236, 99,255,255
    DEFB     16, 16, 16, 16

TILE_SWAMP:
    DEFB    189,219,218,107,167, 53, 52,134
    DEFB    219,181,169, 85,118,203,101,106
    DEFB    139, 21,108,237,149, 52,209,163
    DEFB    237,157, 21,110,182,181,185,219
    DEFB      4,  4,  4,  4

TILE_FORREST:
    DEFB     24, 24, 62, 52,117,122,254,255
    DEFB    250,253,255,251,254,253,247,253
    DEFB    253,123,251,254,255,247,110,126
    DEFB     60, 56, 24, 24,126,126,  0,  0
    DEFB     32, 32, 32, 32

TILE_INN:
    DEFB    255,255,  0,  0,255,255,247,239
    DEFB    128,  1,128,  1,172,165,172,165
    DEFB    170,181,170,181,169,173,169,173
    DEFB    168,165,168,165,128,  1,255,255
    DEFB     56, 56, 56, 56

TILE_ARMOURER:
    DEFB    255,255,248, 57,243,145,228, 99
    DEFB    204, 71,158,139,175, 29,166, 53
    DEFB    164,101,232,245,153,253,207, 57
    DEFB    198, 19,147,231, 58, 15,127,255
    DEFB     56, 56, 56, 56   

TILE_STAIRSU:
    DEFB    244,  4, 20,  4, 31,  4, 17,244
    DEFB     17, 31, 17, 17, 17, 17, 17, 17
    DEFB     17, 17, 17, 17, 17, 17, 17, 17
    DEFB    241, 17,255, 17,255,241,255,255
    DEFB     56, 56, 56, 56

TILE_STAIRSD:
    DEFB    255,255, 31,255, 31,255, 31,255
    DEFB     17,255, 17,255, 17,255, 17, 31
    DEFB     17, 31, 17, 31, 17, 19, 17, 19
    DEFB     17, 19, 17, 18, 17, 18, 17, 18
    DEFB     56, 56, 56, 56

TILE_SEA:
    DEFB      0,  0,  0,  0, 60, 56, 30, 28
    DEFB      0,  0,  7,192,  3,248,  0,192
    DEFB      0,  0,  0,  0, 96,  0, 49,192
    DEFB      0,248,  0,  0,  0,  0,  0,  0
    DEFB     15, 15, 15, 15

TILE_MOUNTAIN:
    DEFB      6,  0,  5,  0,  4,176, 12,232
    DEFB      9,136, 24,196, 16,132, 35,148
    DEFB     33,212, 47, 54,103,146,110,218
    DEFB    100,138, 76,218, 56, 78, 31,248
    DEFB     56, 56, 56, 56

TILE_HILLS:
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB      0,224,  3,208,  6,136,  8,196
    DEFB     49, 98, 68, 49, 74,153,114,158
    DEFB     62, 48,  3, 32,  1,192,  0,  0
    DEFB     32, 32, 32, 32

TILE_GRASS:
    DEFB      0,  2, 40, 32, 72, 68,  0,  4
    DEFB     16,129, 33,  8,  0, 18,100, 16
    DEFB     68,  2,  8,  2,  0, 64,  8,132
    DEFB     32,  8, 65,  1, 18, 24, 32, 32
    DEFB     48, 48, 48, 48

TILE_STRIPES:
    DEFB    227,142,199, 28,142, 56, 28,113
    DEFB     56,227,113,199,227,142,199, 28
    DEFB    142, 56, 28,113, 56,227,113,199
    DEFB    227,142,199, 28,142, 56, 28,113
    DEFB     49, 49, 49, 49

TILE_TABLE:
    DEFB    255,255,128,  1,191,253,160,  5
    DEFB    160,  5,160,  5,160,  5,160,  5
    DEFB    160,  5,160,  5,160,  5,160,  5
    DEFB    160,  5,191,253,128,  1,255,255
    DEFB     48, 48, 48, 48

TILE_DOOR:
    DEFB      0,  0, 31,248, 51,204, 97,134
    DEFB     65,130,193,131,129,129,145,137
    DEFB    145,137,185,157,255,255,129,129
    DEFB    129,129,129,129,129,129,255,255
    DEFB     56, 56, 56, 56

TILE_VLINE:
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB     56, 56, 56, 5
    
TILE_HLINE:
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,255,255
    DEFB    255,255,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB     56, 56, 56, 56

TILE_TLCOR:
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,  0,255
    DEFB      1,255,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB     56, 56, 56, 56

TILE_TRCOR:
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,255,  0
    DEFB    255,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB     56, 56, 56, 56

TILE_BRCOR:
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,255,128
    DEFB    255,  0,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB     56, 56, 56, 56

TILE_BLCOR:
    DEFB      1,128,  1,128,  1,128,  1,128
    DEFB      1,128,  1,128,  1,128,  1,255
    DEFB      0,255,  0,  0,  0,  0,  0,  0
    DEFB      0,  0,  0,  0,  0,  0,  0,  0
    DEFB     56, 56, 56, 56

TILE_PLAYER:
    DEFB    255,255,248, 31,240, 15,224,  7
    DEFB    238,119,224,  7,206,115,202, 83
    DEFB    206,115,192,  3,162, 69, 96,  6
    DEFB    243,207,249,159,252, 63,255,255
    DEFB     56, 56, 56, 56

TILE_OLDMAN:
    DEFB      1,224,  2, 56,  6, 14, 12,  2
    DEFB      8, 51, 63,253, 20, 31, 52, 48
    DEFB     24,112, 17,216, 31,  8, 48, 12
    DEFB     35,  4, 46,  4, 56, 12, 16,  8
    DEFB     56, 56, 56, 56

TILE_GUARD:
    DEFB      3,240,  6, 20, 12, 20,  8, 20
    DEFB      8, 20, 31, 22, 21, 20, 53, 20
    DEFB     25,244, 17, 28, 31,  4,112,228
    DEFB     32,164, 40,228, 56,140, 18,  8
    DEFB     56, 56, 56, 56

TILE_KING:
    DEFB      0,  0,  2,168,  5, 84,  8,  2
    DEFB      8,  2, 30,  4, 53,  4, 33,  4
    DEFB     23,  4, 61,252, 34,  4,124,164
    DEFB     96,164, 40,196, 56,172, 18,  8
    DEFB     56, 56, 56, 56

TILE_TOWNSPEOPLE:
    DEFB      0,  0, 15,240,  8, 92,  8,212
    DEFB      8, 20, 30, 52, 53,  4, 39,  4
    DEFB     23,  4, 61,252, 34,  4, 61,250
    DEFB     17, 18,  9, 20,  8,172, 18, 72
    DEFB     56, 56, 56, 56

TILE_BLANK:
    DEFB     0,0,0,0,0,0,0,0
    DEFB     0,0,0,0,0,0,0,0
    DEFB     0,0,0,0,0,0,0,0
    DEFB     0,0,0,0,0,0,0,0
    DEFB     0,0,0,0   

END MAIN
What I have been trying and failing to do is read the memory locations starting from 32000 -> 32192 that contain all of the tiles on the screen at the time. The idea is I just poke values into these locations when I want to update the screen and as the code can read the locations and print to the screen it should update whenever the memory is changed. This all works.

But What I can't get to work is a simple nestled loop so that the outer loop handles the rows (12) and the inner loop handles the columns (16). to print the tiles on the screen. At the moment I am having to use the manual method of a kind of half way house between a loop and a mess.

The other thing I cannot get to work is a attribute 'diddler', what I want it to do as its reading the value of the memory location, it at the same time as printing the tile, also updates that locations attribute value from a CP ladder. I have tried and I can't seem to figure out a way to get it to work.

So for example, the brick floor, chest should be red paper, black ink, the walls should be white, the sea blue, the grass, trees, green, well you get the idea.

While this is a perfect project for a NIRVANA program, I just want to get the basics down first before jumping off the deep end. :lol:
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Crap 0.1 first assembly project

Post by R-Tape »

I confess I thought you had given up. Your Dragon Quest tile engine looks good but now mission creep is on the cards!

Looks like you've made good progress, maybe 2 weeks without the net would do us all some good.

Your code has this:
LD (HL),32000

What is it supposed to be? Are you trying to load a word into that memory location? In which case it should be LD (HL),0 INC HL, LD (HL),125 for 32000.

If I understand how it works properly, the CP ladder, 'ROLF', would be better if you multiply the tile number by 32 then use that number to find the graphic, and you can use it to find the colour in a table too (if one colour for chess use the tile number directly, if 4 colours per tile as per Dragon Quest then multiply by 4).
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

I guess its all about balance, there are some advantages to no internet, being able to totally focus all of ones leisure time on a 80s programming project does seem to increase productivity. But I lost many hours because I couldn't verify stuff I was doing/could have avoided a bunch of blind alleys. That said overall it was a good experience. Well it was that or watch the first season of Space 1999 again.

The (HL),32000 Is supposed to be loading the value of the first memory location that holds the tilemap data in memory. As you said I have screwed it up :lol: It should be peeking the value in 32000 and loading it into HL.
What I wanted it to do was loop through the range of 192 memory locations and print them on the screen. That is what the HL inc is supposed to be doing. I was wondering why it wouldn't work right lol. I will have a crack at the attribute analyser tomorrow. Once that is done I can apply it to crap chess and that is almost the program done. (with the exception of the input loop.)

Will get crapchess squared away in the next week or so I think, if progress continues at this pace. The plan after that is to take a step backwards as far as technical challenge goes and tackle what really should have been my first project (noughts and crosses ... in assembly with fancy music and graphics lol.) With the routines from crap chess and the dragonquest tile routine I think it would look pretty swish.

That way my first 'game' is crapchess, but I would predict that noughts and crosses would take a matter of days compared to the weeks that crapchess has taken. But its all good experience. To be able to get something out so quickly using the routines/tools is a challenge in it self in discipline. The plan with that is to learn all about custom fonts. That seems to be a logical step in more professional looking programs.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

I am probably missing something obvious here, but my print routine for the noughts and crosses is not behaving properly.

All its got to do is display first the grid with the numbers, then after you hit a key.. it will load the grid without numbers.

But for reasons that escape me its not working.

depending on what way the boards are arranged in the file, determines if the grid will show numbers or blank spaces when the program is run.

Image

Image

Here is the source code.

Code: Select all

ORG 33000

HELP:  DEFB 16,0,22,1,6,17,9,'*',17,3,' ',17,2,'N',17,3,'o',17,4,'u',17,5,'g',17,6,'h',17,7,'t',17,2,'s',17,5,' ',17,3,'&',17,3,' ',17,4,'C',17,5,'r',17,6,'o',17,7,'s',17,2,'s',17,5,'e',17,7,'s',17,3,' ',17,4,'*'
       DEFB 16,7,22,4,15,17,1,'This is noughts',13
       DEFB 22,5,15,'and crosses, for',13 
       DEFB 22,6,15,'two players.',13 
       DEFB 22,8,15,'I will tell you',13
       DEFB 22,9,15,'when either of',13 
       DEFB 22,10,15,'you has won.',13
       DEFB 22,12,15,'The board is',13
       DEFB 22,13,15,'numbered as on',13 
       DEFB 22,14,15,'the left side',13
       DEFB 22,15,15,'of the screen.',13
       DEFB 22,21,2,'PRESS ',18,1,16,2,'<RETURN>',18,0,16,7,' TO CONTINUE...'

BOARD: DEFB 16,2,17,0,22,4,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,5,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,6,1,$8A,' ',16,0,$80,16,2,' ',$8A,' ',16,0,$80,16,2,' ',$85,' ',16,0,$80,16,2,' ',$85,13
       DEFB 22,7,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,8,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,9,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,10,1,$8A,' ',16,0,$80,16,2,' ',$8A,' ',16,0,$80,16,2,' ',$85,' ',16,0,$80,16,2,' ',$85,13
       DEFB 22,11,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,12,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,13,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,14,1,$8A,' ',16,0,$80,16,2,' ',$8A,' ',16,0,$80,16,2,' ',$85,' ',16,0,$80,16,2,' ',$85,13
       DEFB 22,15,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,16,1,$8E,$8C,$8C,$8C,$8E,$8C,$8C,$8C,$8D,$8C,$8C,$8C,$8D,13,17,1,16,8


HELPBOARD:
       DEFB 16,2,17,0,22,4,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,5,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,6,1,$8A,' ',16,3,'1',16,2,' ',$8A,' ',16,3,'2',16,2,' ',$85,' ',16,3,'3',16,2,' ',$85,13
       DEFB 22,7,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,8,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,9,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,10,1,$8A,' ',16,3,'4',16,2,' ',$8A,' ',16,3,'5',16,2,' ',$85,' ',16,3,'6',16,2,' ',$85,13
       DEFB 22,11,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,12,1,$8B,$83,$83,$83,$8B,$83,$83,$83,$87,$83,$83,$83,$87,13
       DEFB 22,13,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,14,1,$8A,' ',16,3,'7',16,2,' ',$8A,' ',16,3,'8',16,2,' ',$85,' ',16,3,'9',16,2,' ',$85,13
       DEFB 22,15,1,$8A,'   ',$8A,'   ',$85,'   ',$85,13
       DEFB 22,16,1,$8E,$8C,$8C,$8C,$8E,$8C,$8C,$8C,$8D,$8C,$8C,$8C,$8D,13,17,1,16,8

EOSTR: equ $
EOHELP: EQU $

EOBOARD: EQU $

MAIN:
       CALL FATFONT
       LD A,14              ; BLUE PAPER (1*8)+WHITE INK 8 = 16
       LD (23693),A         
       LD A,1
       CALL 8859           ; SET BORDER
       CALL 3503           ; CLEAR SCREEN & SET PAPER N INK.
       CALL HELPSCREEN
       CALL KEYBOARDINPUT
       ;CALL GAMELOOP
       ;CALL KEYBOARDINPUT
       JP MAIN

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

FATFONT:
       ld hl,15616         ; ROM font.
       ld de,60000         ; 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,60000-256     ; font minus 32*8.
       ld (23606),hl       ; point to new font.
       ret

KEYBOARDINPUT:
       ld hl,23560         ; 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 DE,BOARD
       LD BC,EOBOARD-BOARD
       CALL 8252
       RET

END MAIN
What is supposed to happen after this is I will scan the keyboard for inputs 1-9, depending on what's pressed, will poke a memory location (the equivalent of variables as used in the basic listing for noughts and crosses games.) then I will just compare the 9 locations for win states (either player getting 3 in a row in some combination).

But until I get this input/print business I can't really progress. It has to be something obvious I am missing, but after a time you keep looking at a problem and can't see the forest for the trees (to paraphrase huey lewis.)
User avatar
Seven.FFF
Manic Miner
Posts: 736
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

EOSTR: equ $
EOHELP: EQU $
EOBOARD: EQU $

All have to be at the end of the respective thing?
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: Wed Jan 24, 2018 5:20 pm EOSTR: equ $
EOHELP: EQU $
EOBOARD: EQU $

All have to be at the end of the respective thing?
I don't understand, I tried them in different places, at the ends of the defbs, I renamed them all the same then it got an error, then i erased all but one and it still didn't work.

What do they actually do anyway? I just want to show the grid with the numbers, the player hits the key, then i clear the grid and will add some extra text later.

Is there a more obvious way to do this? it seems to me to be very confusing way to get information on the screen.

I tried switching the attributes on the grid, using special characters to try and blank the numbers lol. Nothing seems to be working.

Sometimes I think I am going nowhere with this stuff as all of the books and tutorials seem to just progress to much more advance topics - but for me I seem to be stuck at the first hurdle with this stuff lol.

I still don't understand why these input routines, why the print routines are going wrong.
User avatar
Seven.FFF
Manic Miner
Posts: 736
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: 736
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: 736
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: 736
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
Post Reply