Crap 0.1 first assembly project

Show us what you're working on, (preferably with screenshots).
Post Reply
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 03, 2018 5:06 pm Sweet. BTW I think doing the board as a background is sensible.

This is the only downside of using a library - it relieves you from the blood and tears of figuring everything out from first principles... then you just have the blood and tears of figuring out the arcane features of the library!! Hang on in there though. If you've got this far this quick it will all come together pretty quickly :)
I looked at the previous chess programs on the spectrum and a few used the same colour scheme. Agree about the library - that saved a lot of work, plus its nice to have the library code to look at and figure out how someone else got it to work. But you are right - in using the libraries you just transfer the pain of actually grinding out your own solution to a later date where the library can't help you for whatever reason.

The next logical step is to place my pawn sprite on the screen. Once I got that down I will work on the rest of the chessmen. Will also see how much text I can fit along the right hand side... For this I will do it on my Jim Jones first. Once I have satisfied myself I can place graphics willy nilly all over the place I will probably use the fancy library routine that has masking and a whole host of other goodies that would make animation a bit more presentable.

Get the basics straight first then go with the libraries unless I get stuck or its going to take a crazy amount of time to do it alone. And with the sprite/graphics is well worth having a good understanding from the jump start otherwise it seems you are just storing up hurt for later if you don't understand it.

I guess to summarize - libraries are great until you hit a wall and they fail you then you are in just as much a pickle as when you started :D
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 4: (361 days left)

To do a sanity check if my screen layout was ok I did the following... added a bunch of strings on the screen to see if it looked ok..

But the characters seem all borked, I don't understand what has happened.

Image

here is the program code...

Code: Select all

; This program is modified from an example in libzx by Sebastian Mihai, 

main: org 33000					; stay above ULA-contended memory
	jp start					; jump to the beginning of our program
	
	include "libzx/libzx.asm"	; include the libzx library

	stack ds 512				; reserve some bytes for our stack
	endstack:					; mark end of our stack
	
	background_definition:
		incbin "crapbkg.scr"	; the background data is in this file
	
start:
	ld sp, endstack				; set up our new stack (we point to the end 
								; because the stack grows into lower addresses)
	call initialize_libzx		; initialize the libzx library
	
	; this is where the example begins
	
	ld hl, background_definition
	ld de, backgroundVideoBuffer
	call copy_buffer_to_buffer		; copy background definition to 
									; libzx's background buffer
	
	call copy_background_buffer_to_video_ram ; copy libzx's background buffer

player_log:
	ld a, 2
	call 5633
	ld de, string
	ld bc, eostr-string
	ld de, infostring
	ld bc, eostr-infostring
	call 8252
											 ; to the video ram
infinite_loop:
	jp infinite_loop			; lock CPU

infostring: defb 16, 2, 17, 0, 22, 21, 9, 91,32,69,110,116,101,114,32,87,104,105,116,101,32,109,110,118,101,46,32,93 
string:  defb 16, 3, 22, 3, 21, " d2- d4,"
	defb 22, 4, 21, " e2- d4,"
	defb 22, 5, 21, " f2- d4,"
	defb 22, 6, 21, " g2- d4,"
	defb 22, 7, 21, " h2- d4,"
	defb 22, 8, 21, " a2- d4,"
	defb 22, 9, 21, " b2- d4,"
	defb 22, 10, 21, " c2- d4,"
	defb 22, 11, 21, " d1- e3,"
	defb 22, 12, 21, " g1- f3,"
	defb 22, 13, 21, " d2- d4,"
eostr:	equ $
	
end main
I must have screwed up when drawing the background. I will redraw the background and see if that makes any difference later.
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 »

Does copy background to videoram set HL, DE, BC in the routine? If BC is more than 6912 it will do the screen but then carry on & spunk data all over the system variables - including the fontseed (23606/7) which should be 0,60.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

R-Tape wrote: Thu Jan 04, 2018 5:55 am Does copy background to videoram set HL, DE, BC in the routine? If BC is more than 6912 it will do the screen but then carry on & spunk data all over the system variables - including the fontseed (23606/7) which should be 0,60.
I will check now.

This is the tap file.

https://nofile.io/f/EC5xmrueVJy/test5.tap

I can't break the program to peek at the memory locations requested...

These are the libzx libraries for the bitmaps.asm..

Code: Select all

;------------------------------------------------------------------------------
; This file is part of the ZX Spectrum libzx library by Sebastian Mihai, 2016
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;
; Aggregates all bitmaps and bitmap buffer (background, screen) routines
;
; There are duplicate routines targeting the background buffer and the screen
; buffer. The reason for duplication is performance.
; 
; +-------------------+
; |                   |
; | background buffer |-----
; |                   |     \         +--------------+
; +-------------------+      -------->|              |
;                                     | video memory |
; sprites drawn directly ------------>|              |
; to video ram, appearing             +--------------+
; in "front" of the background
;
; Copying a chunk of the background buffer to the video memory, followed 
; immediately by drawing a bitmap directly to the video memory achieves
; "movable" sprites that don't "erase" the background when they move.
;
;------------------------------------------------------------------------------

	;--------------------------------------------------------------------------
	; Constants and data used by all bitmap routines
	;--------------------------------------------------------------------------
	VISIBLE_VIDEO_MEMORY equ 16384	; start of the video ram
	VIDEO_SEGMENT_SIZE equ 2048		; size in bytes of a third of a screen
	VIDEO_SEGMENT_LINES equ 64		; horizontal lines in a segment
	VIDEO_ATTRIBUTES_SIZE equ 768	; size in bytes of the attributes area
	VIDEO_TOTAL_SIZE equ 3*VIDEO_SEGMENT_SIZE + VIDEO_ATTRIBUTES_SIZE
	VISIBLE_ATTRIBUTES_MEMORY equ VISIBLE_VIDEO_MEMORY + 3*VIDEO_SEGMENT_SIZE
	
	; used to look up video memory addresses in the background buffer
	video_memory_Y_lookup_background ds 192*2
						; reserve 2 bytes for each of the 192
						; possible screen Y values
	
	; used to look up video memory addresses in the video ram
	video_memory_Y_lookup_vram ds 192*2
						; reserve 2 bytes for each of the 192
						; possible screen Y values

	; the background buffer is used to keep sprites from "erasing" the space
	; behind them as they move
	backgroundVideoBuffer:
		videoBufferPixelData ds VIDEO_TOTAL_SIZE-VIDEO_ATTRIBUTES_SIZE
		videoBufferAttributeData ds VIDEO_ATTRIBUTES_SIZE, %00111000
		
	BUFFER_TO_SCREEN_OFFSET equ VISIBLE_VIDEO_MEMORY - backgroundVideoBuffer

	;--------------------------------------------------------------------------
	; Includes
	;--------------------------------------------------------------------------
	include "libzx/bitmaps/bitmaps_vram.asm"
	include "libzx/bitmaps/bitmaps_background.asm"
	
	include "libzx/bitmaps/bitmaps_vram_or_masked.asm"
	include "libzx/bitmaps/bitmaps_vram_or.asm"
	include "libzx/bitmaps/bitmaps_vram_xor.asm"
	include "libzx/bitmaps/bitmaps_vram_not_and.asm"
	
	include "libzx/bitmaps/bitmaps_background_or.asm"
	include "libzx/bitmaps/bitmaps_background_xor.asm"
	include "libzx/bitmaps/bitmaps_background_not_and.asm"
	include "libzx/bitmaps/bitmaps_background_or_masked.asm"

	include "libzx/bitmaps/bitmaps_buffer.asm"
	include "libzx/bitmaps/bitmaps_utilities.asm"
	include "libzx/bitmaps/bitmaps_colours.asm"
so its just loading a bunch of other files... the ones I think its using is the top two vram and bitmaps background...

bitmap_background.asm

Code: Select all

;------------------------------------------------------------------------------
; This file is part of the ZX Spectrum libzx library by Sebastian Mihai, 2016
;------------------------------------------------------------------------------

; Meant to be called before any sprite functionality is used, 
; it initializes sprite routines, including:
;     - pre-computing video memory addresses for each horizontal line
;
initialize_bitmaps:
	; pre-compute video memory addresses for each of the 192 horizontal
	; display lines
	; each stored address is of the first byte of each line (which represents
	; the left-most 8x8 pixel square of each line)
	
	ld b, 0				; we zero out B because C is enough for 192 lines
	ld c, 0				; this will be our counter, going from 0 to 191
	
compute_video_memory_Y_loop:
	push bc
	
	ld l, c
	call get_video_Y	; get address of line in L (returned in HL)
	
	ld d, h
	ld e, l				; DE := address of first square on B horizontal line
	
	pop bc				; get_video_Y destroys B and C, so restore them
	ld hl, video_memory_Y_lookup_background
	add hl, bc
	add hl, bc			; HL := video_memory_Y_lookup + 2*(current Y)
	
	ld (hl), d
	inc hl
	ld (hl), e			; (HL) := word DE
						
	inc c
	ld a, c
	cp 192
	jp nz, compute_video_memory_Y_loop	; if C != 192, compute video memory
										; for next horizontal line down
	ret

	
; Given a screen Y coordinate, calculate the video memory address
; which represents the first pixel on that line.
; 
; Input:	
; 		L - screen Y coordinate
; Output:
; 		HL - video memory address of beginning of Y line
get_video_Y:
	; where y is the screen coordinate in each sector
	;
	; since the 192 pixel tall screen is divided into 3 sectors,
	; then each sector is 64 pixels tall
	;
	; MEMORY Y = (beginning of screen sector) + ( y/8 + 8*(y%8) )*32
	;          = (beginning of screen sector) + ( y>>3 + 8*(y AND 7) )*32
	;          = (beginning of screen sector) + ( y>>3 + (y AND 7)<<3 )*32
	;          = (beginning of screen sector) + ( y>>3 + (y AND 7)<<3 )<<5
	ld e, l			; E := overall screen y (we'll need this later)
	
	ld h, 0			; y coordinates are between 0 and 191, so 
					; they don't need register H
	
	ld a, l
	and 63			; A := y (in sector, since sectors are 64 pixels tall)
	ld l, a			; L := y (in sector, since sectors are 64 pixels tall)
	
	and 7			; A := y AND 7
	sla a
	sla a
	sla a			; A := (y AND 7)<<3
	
	srl l
	srl l
	srl l			; HL := y>>3
	
	ld b, 0
	ld c, a			; BC := (y AND 7)<<3
	add hl, bc		; HL := y>>3 + (y AND 7)<<3
	
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; HL := ( y>>3 + (y AND 7)<<3 )<<5
	
	ld bc, backgroundVideoBuffer
	add hl, bc		; HL := VRAM BASE + ( y>>3 + (y AND 7)<<3 )<<5
	
	; now, depending on where the initial screen y value puts us
	; (which of the three vertical screen segments),
	; offset the memory y location we're returning
	;
	; since there are three segments, we can offset at most by two
	
	ld bc, VIDEO_SEGMENT_SIZE ; we'll offset each time by this much
	
	ld a, e					; A := screen y
	sub VIDEO_SEGMENT_LINES	; A := A - lines per segment
	jp M, get_video_Y_done	; no left over lines
	add hl, bc				; offset by one screen segment
	sub VIDEO_SEGMENT_LINES ; A := A - lines per segment
	jp M, get_video_Y_done	; no left over lines
	add hl, bc				; offset by a second screen segment
	
get_video_Y_done:
	ret
bitmaps_vram.asm

Code: Select all

;------------------------------------------------------------------------------
; This file is part of the ZX Spectrum libzx library by Sebastian Mihai, 2016
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
; These routines operate directly on the video ram.
; They are meant to draw foreground items, such as sprites.
; They are called right after the background buffer is fast-copied to the
; video ram.
;------------------------------------------------------------------------------
	
; Meant to be called before any sprite functionality is used, 
; it initializes sprite routines, including:
;     - pre-computing video memory addresses for each horizontal line
;
initialize_bitmaps_vram:
	; pre-compute video memory addresses for each of the 192 horizontal
	; display lines
	; each stored address is of the first byte of each line (which represents
	; the left-most 8x8 pixel square of each line)
	
	ld b, 0				; we zero out B because C is enough for 192 lines
	ld c, 0				; this will be our counter, going from 0 to 191
	
compute_video_memory_Y_loop_vram:
	push bc
	
	ld l, c
	call get_video_Y_vram	; get address of line in L (returned in HL)
	
	ld d, h
	ld e, l				; DE := address of first square on B horizontal line
	
	pop bc				; get_video_Y destroys B and C, so restore them
	ld hl, video_memory_Y_lookup_vram
	add hl, bc
	add hl, bc			; HL := video_memory_Y_lookup_vram + 2*(current Y)
	
	ld (hl), d
	inc hl
	ld (hl), e			; (HL) := word DE
						
	inc c
	ld a, c
	cp 192
	jp nz, compute_video_memory_Y_loop_vram	; if C != 192, compute video memory
										; for next horizontal line down
	ret	
	
		
; Given a screen Y coordinate, calculate the video memory address
; which represents the first pixel on that line.
; 
; Input:	
; 		L - screen Y coordinate
; Output:
; 		HL - video memory address of beginning of Y line
get_video_Y_vram:
	; where y is the screen coordinate in each sector
	;
	; since the 192 pixel tall screen is divided into 3 sectors,
	; then each sector is 64 pixels tall
	;
	; MEMORY Y = (beginning of screen sector) + ( y/8 + 8*(y%8) )*32
	;          = (beginning of screen sector) + ( y>>3 + 8*(y AND 7) )*32
	;          = (beginning of screen sector) + ( y>>3 + (y AND 7)<<3 )*32
	;          = (beginning of screen sector) + ( y>>3 + (y AND 7)<<3 )<<5
	ld e, l			; E := overall screen y (we'll need this later)
	
	ld h, 0			; y coordinates are between 0 and 191, so 
					; they don't need register H
	
	ld a, l
	and 63			; A := y (in sector, since sectors are 64 pixels tall)
	ld l, a			; L := y (in sector, since sectors are 64 pixels tall)
	
	and 7			; A := y AND 7
	sla a
	sla a
	sla a			; A := (y AND 7)<<3
	
	srl l
	srl l
	srl l			; HL := y>>3
	
	ld b, 0
	ld c, a			; BC := (y AND 7)<<3
	add hl, bc		; HL := y>>3 + (y AND 7)<<3
	
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; shift left one
	add hl, hl		; HL := ( y>>3 + (y AND 7)<<3 )<<5
	
	ld bc, VISIBLE_VIDEO_MEMORY
	add hl, bc		; HL := VRAM BASE + ( y>>3 + (y AND 7)<<3 )<<5
	
	; now, depending on where the initial screen y value puts us
	; (which of the three vertical screen segments),
	; offset the memory y location we're returning
	;
	; since there are three segments, we can offset at most by two
	
	ld bc, VIDEO_SEGMENT_SIZE ; we'll offset each time by this much
	
	ld a, e					; A := screen y
	sub VIDEO_SEGMENT_LINES	; A := A - lines per segment
	jp M, get_video_Y_vram_done	; no left over lines
	add hl, bc				; offset by one screen segment
	sub VIDEO_SEGMENT_LINES ; A := A - lines per segment
	jp M, get_video_Y_vram_done	; no left over lines
	add hl, bc				; offset by a second screen segment
	
get_video_Y_vram_done:
	ret
Is there a straightforward way to load the background without all these library files? I just want to load the binary into the background.

In other news relating to the project, I got pasmo to assemble the msx rom today. So the plan is when I get stuck on one platform i will just bounce between them that will give me something to do when I am stuck on one part I think. While childish I did grin excessively when the "crap chess MSX" loaded for the first time.

Image
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: Thu Jan 04, 2018 6:14 am Is there a straightforward way to load the background without all these library files? I just want to load the binary into the background.
Jeepers, man, of course there is! Simply LDIR it. If that’s all you need, then what you’ve been doing so far is utter madness. :lol:

Code: Select all

	ld bc,$1830		;length of block to copy
	ld hl,your_screen_file	;source address
	ld de,$4000		;destination address
	ldir			;copy BC bytes from HL to DE
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: Thu Jan 04, 2018 8:27 am Jeepers, man, of course there is! Simply LDIR it. If that’s all you need, then what you’ve been doing so far is utter madness. :lol:

Code: Select all

	ld bc,$1830		;length of block to copy
	ld hl,your_screen_file	;source address
	ld de,$4000		;destination address
	ldir			;copy BC bytes from HL to DE
Cheers!

And with that a semblance of sanity returns to the project...

Image

Well never did get dem der sprites on the screen but that issue with the background set me back. Still live and learn. the 4 lines of assembly there replaced a great deal of library code so its a plus right there.

Had to fiddle with the length of the data being sent, as I had more attribute data to send through. Still after a bit of wiggling the code all was well.

The chess notation at the side looks messy, I am thinking to have that as a separate screen or a pop-out window. Anyway that is a task for later. Like I said earlier the next thing is to get the damn chessmen on the board finally. :lol:

Image
Last edited by Nomad on Thu Jan 04, 2018 11:34 am, edited 1 time in total.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Crap 0.1 first assembly project

Post by AndyC »

In fairness, what libzx is doing in the background is setting everything up so you can use it's sprite routines to handle things and they'll know what is supposed to be in the background and how to restore it - mixing and matching that with your own drawing code is likely to be problematic.

The upside of doing your own drawing, of course, is that if you do try to port it to something else you're going to have to know how to do it anyway (and the screen format on platforms like the CPC makes the Speccy seem trivial!)
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 think the library routines are overcomplicating things (well I can't follow what's going on!).

Not saying this is the best way to do, but here's how I'd go about this (no library routines, no buffer):


call setborder
call clearscreen
call paperfill
call brickborder ;use UDGs and ROM routines
call printtext ;ROM routines
call drawchessboard ;custom routine to draw attribute chess board
call drawchessmap ;draw contents of chessmap including empty spaces

chessmap:
db 8,9,10,11,12,10,9,8 ;black pieces tiles 7-12
db 7,7,7,7,7,7,7,7
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 1,1,1,1,1,1,1,1 ;white pieces tiles 1-6
db 2,3,4,5,6,4,3,2
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 »

R-Tape wrote: Thu Jan 04, 2018 10:57 am I think the library routines are overcomplicating things (well I can't follow what's going on!).
Completely agree! Chucking everything in there along with the kitchen sink just seemed to make a mess. I lost track of the project and what was being learned along the way ages ago.

Go back to basics. Work out what you want to achieve bit by bit and ask if you don't know how to do it. Drawing a checkerboard and putting some static sprites in it really doesn't require resorting to libraries, and you won't learn a great deal if that's the path you take.
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 »

dfzx wrote: Thu Jan 04, 2018 12:43 pm
R-Tape wrote: Thu Jan 04, 2018 10:57 am I think the library routines are overcomplicating things (well I can't follow what's going on!).
Completely agree! Chucking everything in there along with the kitchen sink just seemed to make a mess. I lost track of the project and what was being learned along the way ages ago.

Go back to basics. Work out what you want to achieve bit by bit and ask if you don't know how to do it. Drawing a checkerboard and putting some static sprites in it really doesn't require resorting to libraries, and you won't learn a great deal if that's the path you take.
Nomad wrote: Sat Dec 30, 2017 2:58 pm <snip>
In the spirit of crap games, you will need two players, who enter there moves via the keyboard (none of that cursor stuff... well not at the moment anyway..). Because there is no chess computer - no complicated AI, and all that other headache causing stuff. All the 'game' will do is accept user input from the two players, and move the chessmen/pawns about the board, removing the pieces when needed.

That will just require a non-vacant square check, if non-vacant remove the piece from the board and replace with the new piece. pretty simple.

But like a fool I decided to tackle the background first. (well it pretty...)

The assembly code was based of a checker pattern program I found on you tube and abused...

Next task is to create the sprites, then the input, then think about the animation, then the 'rules'. mmmmm will add some more cosmetic fluff like a title bar, infobar at the bottom, to make it less of a cheat i will set the border, paper, in the assembly portion and not the basic boot loader next time also.
<snip>
The project is to replicate the cash-grab type titles you used to get in the magazines for around a fiver. It needs to be good enough that a person from that era would not demand a refund. Just enough. The restrictions I placed on myself was to use assembly, make the program something that my 6 year old self couldn't have done in basic.

Like I said at the start, the program is chess for two players. (that is where the crap part of the crap game comes in.. why not just play on a real board?.. reasons.) The players can see the moves they have made during the game on the right hand side of the board.

I resorted to using the libzx because I saw there was an example of loading a background. But point taken I couldn't figure out what was going on with the library either. That is not a knock on the fella's library more on my assembly comprehension. Plus its always harder to understand someone else's work I think. Going back to why I used the library - it had a bunch of other useful sprite masking routines that would have come in handy when animating the sprites.

But in the end I just used the background code supplied (the 4 lines). The project at the moment does not use any libraries.

Here is the listing.

Code: Select all

main: org 33000	  
	jp start	

	background_definition:
		incbin "crapbkg2.scr"	; the background data is in this file
	
start:
	ld a,2           ; Set the colour to red (2).
    	call 8859       ; Set permanent border colours.
    	call 3503       ; Clear the screen, open channel 2.

	ld bc,$1B30		;length of block to copy
	ld hl,background_definition	;source address
	ld de,$4000		;destination address
	ldir			;copy BC bytes from HL to DE

player_log:   ; this suposedly prints the strings all over the page
	ld a, 2
	call 5633			
	ld de, string			; get the players moves
	ld bc, eostr-string		; figure the length
	ld de, infostring		; get the infomation to player
	ld bc, eostr-infostring		; figure the length
	call 8252			; make the rom call
											 ; to the video ram
infinite_loop:
	jp infinite_loop			; round and round and round we go...

infostring: defb 16, 2, 17, 6, 22, 21, 9, "White to move..." ; this is the information bar at the bottom of the screen
;this is the players moves - when the game is finished it will be updated from the input but for now its just placeholder stuff.
string:  defb 16, 3, 17, 0, 22, 3, 21, "e4v bd6" 
	defb 22, 4, 21, "d4 Nf6" 
	defb 22, 5, 21, "Nc3 Nbd7" 
	defb 22, 6, 21, "Nf3 e5" 
	defb 22, 7, 21, "Bc4 exd4" 
	defb 22, 8, 21, "Nxd4 Ne5" 
	defb 22, 9, 21, "Be2 Be7" 
	defb 22, 10, 21, "O-O Bd7"
	defb 22, 11, 21, "f4 Ng6"
	defb 22, 12, 21, "Be3 O-O"
	defb 22, 13, 21, "Qd3 c6"
	defb 22, 14, 21, "h3 d5"
	defb 22, 15, 21, "e5 Ne8"
	defb 22, 16, 21, "g4 Nc7"
	defb 22, 17, 21, "Nf3 Re8"
	defb 22, 18, 21, "f5 Nf8"
	defb 22, 19, 21, "g5 b5"	
eostr:	equ $
	
end main
This is the main screen, will add the menu screen and input after the sprites are done. but user input and the menu are complete, along with the music. I just need to combine them. Not that impressive granted but then its early days yet.
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: Thu Jan 04, 2018 2:02 pm

Code: Select all

	ld bc,$1B30		;length of block to copy
Sorry, I made a mistake (doing some dec to hex conversion in my head), and you only partially corrected it. The length should be $1b00 (6912 in dec). Copying 48 extra bytes is not super critical, but it’s best not to overwrite this area unless you really need to. On the Spectrum 48K, this is normally the printer buffer (but can also be reclaimed by certain peripherals).
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: Thu Jan 04, 2018 2:42 pm
Nomad wrote: Thu Jan 04, 2018 2:02 pm

Code: Select all

	ld bc,$1B30		;length of block to copy
Sorry, I made a mistake (doing some dec to hex conversion in my head), and you only partially corrected it. The length should be $1b00 (6912 in dec). Copying 48 extra bytes is not super critical, but it’s best not to overwrite this area unless you really need to. On the Spectrum 48K, this is normally the printer buffer (but can also be reclaimed by certain peripherals).
Thanks; I will fix that now.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 5: (360 days left)

Progress was OK today, I managed to 'refactor' the code so now it is a little less of a mess. Next thing that got done, I created a table of all the possible positions for the graphics on the board. So now no more guess work - if I want A6 I know exactly where it is on the screen.

https://nofile.io/f/KC1XyR1ysc8/boardxy.pdf

This is my reference for figuring out the square positions on the board.

This was to help create my square highlighter, but I realised after I can use it for positioning of the chessmen on the board also. So it was more useful than I had imagined at first.

As you can see from the programming questions I kinda got stuck with the whole drawing the chessmen on the screen (or should I say, loading the data into the video ram). I moved on to a part of the program I knew I could complete and cracked on with that.

So today was spent working on the square highlighter functions. For each square of the board I want to be able to highlight the square. So I needed to know the positions for each of the squares on the board, so I could write the colour data to the attribute data of the memory.

Everything went to plan, however as I was coding the routines I realised that having a table and a single macro would have been a better approach. But for now will just finish the routines using the naive approach and figure out the lookup table/macro idea later.

Here is a taste of what I have been up to..

Image

In this case I was highlighting H8, just to confuse the code below is for A8.. but you get the idea.

Code: Select all

HIGHLIGHTBOARDA8:
	ld hl, 22528+132			; top left
	ld (hl), 30					; purple highlight
	ld hl, 22528+133			; top right
	ld (hl), 30					; purple highlight
	ld hl, 22528+164			; bottom left
	ld (hl), 30					; purple highlight
	ld hl, 22528+165			; bottom right
	ld (hl), 30					; purple highlight
	ret
Now just have to finish the rest of the board... another immediate change is using a constant instead of hard-coding the purple highlight colour. That will be painful to go back and edit for all of the square otherwise...
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Forgot the most important part, the tap! You can see the highlighter running along blacks back rank. R-tapes sounds are also present.

https://nofile.io/f/0qHvna9nbtC/test6.tap
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Made a lot of progress this evening thanks to the help of all you kind fellows.
Image

While you can't see them - there are 32 chessmen all on the board in the right place. The issue is I assumed that the chessmen would over write the board background but I was wrong. There is an attribute issue that I need to fix. (well that is my guess.) You can see the line of rooks at the top because the highlighter is showing the back row.

hunch there is probably a step I am missing.

Still its great to see the little blighter's on the screen even if I have to switch off the background to do it..

Image
See... there hiding.

Now granted I still need to create the sprites for the rest of the chessmen. figure out the attribute issues but the major hurdle has been overcome.
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 »

Congrats! And you could just use the sprites you have as an innovative chess variant - RookPawn. Or something.

I don't follow - what's the crack with the attribute problem?
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 »

Hint: All hail the mighty XOR.
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.
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 »

Nice one. This is already a non-crap game :))))

I think the attribute problem is just that you have to merge the piece colour with the board colour when you draw them.

You'll have to pick a non-white colour for the white pieces, say red, so there are four permutations:

Code: Select all

black piece on a white square = %01 111 000 =  56
black piece on a green square = %01 100 000 =  96
red   piece on a white square = %01 111 010 = 122
red   piece on a green square = %01 100 010 =  98
                                  ^ ^^^ ^^^
                                  B PPP III                                  

B = Bright
P = Paper
I = Ink

Your formulae for the attribute is Ink + (Paper * 8) + 64.

There's a number of ways you can do it, with additions or masking (and, or, xor, etc).
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 »

Ast A. Moore wrote: Fri Jan 05, 2018 7:11 pm Hint: All hail the mighty XOR.
Ahh so i end up with a 'cut out' from the background.. will need to figure out how to do that :)
R-Tape wrote: Fri Jan 05, 2018 7:07 pm Congrats! And you could just use the sprites you have as an innovative chess variant - RookPawn. Or something.

I don't follow - what's the crack with the attribute problem?
Yes I guess it could be used for like a chess tutor / chess problems. Then there is always pawn apocalypse. :)

The problem with the attributes is ... well my theory really only works for the white squares as they would be the same colour.. I really am not sure what the issue is with the green squares...
Seven.FFF wrote: Fri Jan 05, 2018 7:18 pm Nice one. This is already a non-crap game :))))

I think the attribute problem is just that you have to merge the piece colour with the board colour when you draw them.

You'll have to pick a non-white colour for the white pieces, say red, so there are four permutations:

Code: Select all

black piece on a white square = %01 111 000 =  56
black piece on a green square = %01 100 000 =  96
red   piece on a white square = %01 111 010 = 122
red   piece on a green square = %01 100 010 =  98
                                  ^ ^^^ ^^^
                                  B PPP III                                  

B = Bright
P = Paper
I = Ink

Your formulae for the attribute is Ink + (Paper * 8) + 64.

There's a number of ways you can do it, with additions or masking (and, or, xor, etc).
Ahh Ok, so I will need to edit the background then...

Code: Select all

main: org $80e8	  		; (33000)
	jp start	

start:
	call SETHELPSCREEN
	call SETMAINSCREEN		; calls the subroutine SETMAINSCREEN
	call HIGHLIGHTBOARDA8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDB8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDC8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDD8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDE8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDF8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDG8
	call SFX
	call SETMAINSCREEN
	call HIGHLIGHTBOARDH8
	call SFX
	call NEVERENDINGSTORY		; calls the subroutine NEVERENDINGSTORY										


NEWGAMEPLACECHESSMEN:
	ld b,4
	ld c,4
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,6
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,8
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,10
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,12
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,14
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,16
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,4
	ld c,18
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,6
	ld c,4
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,6
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,8
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,10
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,12
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,14
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,16
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,6
	ld c,18
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile

	ld b,18
	ld c,4
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,6
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,8
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,10
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,12
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,14
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,16
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,18
	ld c,18
	call yx2cell
	ld hl,tilegraphic_rook
	call drawtile
	ld b,16
	ld c,4
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,6
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,8
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,10
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,12
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,14
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,16
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	ld b,16
	ld c,18
	call yx2cell
	ld hl,tilegraphic_pawn
	call drawtile
	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
	
tilegraphic_pawn:
	db	0,0
	db	0,0
	db	0,0
	db	0,0
	db	0,0
	db	3,192
	db	7,224
	db	7,224
	db	7,224
	db	3,192
	db	1,128
	db	1,128
	db	1,128
	db	3,192
	db	7,224
	db	0,0

tilegraphic_rook:
	db	0,0
	db	0,0
	db	0,0
	db	0,0
	db	10,80
	db	15,240
	db	7,224
	db	3,192
	db	3,192
	db	3,192
	db	3,192
	db	3,192
	db	3,192
	db	7,224
	db	15,240
	db	0,0

background_definition:
	incbin "crapbkg2.scr"	; the background data is in this file


helpstring: defb 16, 8, 17, 0, 22, 3, 4, "If you have an issue, here is a tissue..."
	defb 16, 7, 17, 0, 22, 4, 4, "If you have an issue, here is a tissue..."
	defb 16, 6, 17, 0, 22, 5, 4, "If you have an issue, here is a tissue..."
	defb 16, 5, 17, 0, 22, 6, 4, "If you have an issue, here is a tissue..."
	defb 16, 4, 17, 0, 22, 7, 4, "If you have an issue, here is a tissue..."
	defb 16, 3, 17, 0, 22, 8, 4, "If you have an issue, here is a tissue..."
	defb 16, 2, 17, 0, 22, 9, 4, "If you have an issue, here is a tissue..."
	defb 16, 1, 17, 0, 22, 10, 4, "If you have an issue, here is a tissue..."
	defb 16, 8, 17, 0, 22, 11, 4, "If you have an issue, here is a tissue..."
	defb 16, 7, 17, 0, 22, 12, 4, "If you have an issue, here is a tissue..."
	defb 16, 6, 17, 0, 22, 13, 4, "If you have an issue, here is a tissue..."

infostring: defb 16, 2, 17, 6, 22, 21, 9, "White to move..." ; this is the information bar at the bottom of the screen
;this is the players moves - when the game is finished it will be updated from the input but for now its just placeholder stuff.

string: defb 16, 3, 17, 0, 22, 3, 21, "e4v bd6" 
	defb 22, 4, 21, "d4 Nf6" 
	defb 22, 5, 21, "Nc3 Nbd7" 
	defb 22, 6, 21, "Nf3 e5" 
	defb 22, 7, 21, "Bc4 exd4" 
	defb 22, 8, 21, "Nxd4 Ne5" 
	defb 22, 9, 21, "Be2 Be7" 
	defb 22, 10, 21, "O-O Bd7"
	defb 22, 11, 21, "f4 Ng6"
	defb 22, 12, 21, "Be3 O-O"
	defb 22, 13, 21, "Qd3 c6"
	defb 22, 14, 21, "h3 d5"
	defb 22, 15, 21, "e5 Ne8"
	defb 22, 16, 21, "g4 Nc7"
	defb 22, 17, 21, "Nf3 Re8"
	defb 22, 18, 21, "f5 Nf8"
	defb 22, 19, 21, "g5 b5"	

eostr:	equ $

board: 	defb 2, 3, 4, 6, 5, 4, 3, 2
	defb 1, 1, 1, 1, 1, 1, 1, 1
	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 1, 1, 1, 1, 1, 1, 1, 1
	defb 2, 3, 4, 6, 5, 4, 3, 2

SETTEXT:				; sets up the text on the main screen
	call SETPLAYERMOVELIST		; calls the subroutine SETPLAYERMOVELIST
	call SETPROGRAMOUTPUT		; calls the subroutine SETPROGRAMOUTPUT
	ret				; return

SETBORDER: 				; sets the colour of the border
	ld a,d 				; Set the colour to red (2).
    	call $229b       		; (8859) Set permanent border colours.
	ret				; return

CLEARSCREEN:				; clears the screen
	ld a,71                         ; White ink (7), black paper (0), bright (64).
    	ld (23693),a                    ; Set our screen colours.
    	xor a                           ; Load accumulator with zero.
    	call 8859                       ; Set permanent border colours.
    	call 3503 	                ; Clear the screen, open channel 2.
;	call $daf       		; (3503) Clear the screen, open channel 2.
	ret				; return

SFX:
zap:
	ld d,16		;speaker = bit 4
	ld e,0		;distance between speaker move counter
	ld b,255	;overall length counter
blp0:	ld a,d
	;and 248		;keep border colour the same
	out (254),a	;move the speaker in or out depending on bit 4
	cpl		;toggle, so we alternative between speaker in and out to make sound
	ld d,a		;store it
	ld c,e		;now a pause
blp1:	dec c
	jr nz,blp1
	dec e		;change to inc e to reverse the sound, or remove to make it a note
	djnz blp0	;repeat B=255 times
	ret

HIGHLIGHTBOARDA8:
	ld hl, 22528+132
	ld (hl), 30
	ld hl, 22528+133
	ld (hl), 30
	ld hl, 22528+164
	ld (hl), 30
	ld hl, 22528+165
	ld (hl), 30
	ret

HIGHLIGHTBOARDB8:
	ld hl, 22528+134
	ld (hl), 30
	ld hl, 22528+135
	ld (hl), 30
	ld hl, 22528+166
	ld (hl), 30
	ld hl, 22528+167
	ld (hl), 30
	ret

HIGHLIGHTBOARDC8:
	ld hl, 22528+136
	ld (hl), 30
	ld hl, 22528+137
	ld (hl), 30
	ld hl, 22528+168
	ld (hl), 30
	ld hl, 22528+169
	ld (hl), 30
	ret

HIGHLIGHTBOARDD8:
	ld hl, 22528+138
	ld (hl), 30
	ld hl, 22528+139
	ld (hl), 30
	ld hl, 22528+170
	ld (hl), 30
	ld hl, 22528+171
	ld (hl), 30
	ret

HIGHLIGHTBOARDE8:
	ld hl, 22528+140
	ld (hl), 30
	ld hl, 22528+141
	ld (hl), 30
	ld hl, 22528+172
	ld (hl), 30
	ld hl, 22528+173
	ld (hl), 30
	ret

HIGHLIGHTBOARDF8:
	ld hl, 22528+142
	ld (hl), 30
	ld hl, 22528+143
	ld (hl), 30
	ld hl, 22528+174
	ld (hl), 30
	ld hl, 22528+175
	ld (hl), 30
	ret

HIGHLIGHTBOARDG8:
	ld hl, 22528+144
	ld (hl), 30
	ld hl, 22528+145
	ld (hl), 30
	ld hl, 22528+176
	ld (hl), 30
	ld hl, 22528+177
	ld (hl), 30
	ret

HIGHLIGHTBOARDH8:
	ld hl, 22528+146
	ld (hl), 30
	ld hl, 22528+147
	ld (hl), 30
	ld hl, 22528+178
	ld (hl), 30
	ld hl, 22528+179
	ld (hl), 30
	ret

HIGHLIGHTBOARDA7:
	ld hl, 22528+196
	ld (hl), 30
	ld hl, 22528+197
	ld (hl), 30
	ld hl, 22528+228
	ld (hl), 30
	ld hl, 22528+229
	ld (hl), 30
	ret

HIGHLIGHTBOARDA6:
	ld hl, 22528+260
	ld (hl), 30
	ld hl, 22528+261
	ld (hl), 30
	ld hl, 22528+292
	ld (hl), 30
	ld hl, 22528+293
	ld (hl), 30
	ret

HIGHLIGHTBOARDA5:
	ld hl, 22528+324
	ld (hl), 30
	ld hl, 22528+325
	ld (hl), 30
	ld hl, 22528+356
	ld (hl), 30
	ld hl, 22528+357
	ld (hl), 30
	ret

HIGHLIGHTBOARDA4:
	ld hl, 22528+388
	ld (hl), 30
	ld hl, 22528+389
	ld (hl), 30
	ld hl, 22528+420
	ld (hl), 30
	ld hl, 22528+421
	ld (hl), 30
	ret

HIGHLIGHTBOARDA3:
	ld hl, 22528+452
	ld (hl), 30
	ld hl, 22528+453
	ld (hl), 30
	ld hl, 22528+484
	ld (hl), 30
	ld hl, 22528+485
	ld (hl), 30
	ret

HIGHLIGHTBOARDA2:
	ld hl, 22528+516
	ld (hl), 30
	ld hl, 22528+517
	ld (hl), 30
	ld hl, 22528+548
	ld (hl), 30
	ld hl, 22528+549
	ld (hl), 30
	ret

HIGHLIGHTBOARDA1:
	ld hl, 22528+580
	ld (hl), 30
	ld hl, 22528+581
	ld (hl), 30
	ld hl, 22528+612
	ld (hl), 30
	ld hl, 22528+613
	ld (hl), 30
	ret

SETMAINBACKGROUND:			; sets the main screen background
	ld bc,$1b00			;length of block to copy
	ld hl,background_definition	;source address
	ld de,$4000			;destination address
	ldir				;copy BC bytes from HL to DE
	ret				; return

SETPLAYERMOVELIST:			; prints the player move list
	ld a, 2				; loads 2 into register A
	call $1601			; (5633) 
	ld de, string			; get the players moves
	ld bc, eostr-string		; figure the length
	call $203c			; (8252) make the rom call
	ret				; return

SETPROGRAMOUTPUT:			; prints the program output (prompts)
	ld a, 2				; loads 2 into register A
	call $1601			; (5633) 
	ld de, infostring		; get the infomation to player
	ld bc, eostr-infostring		; figure the length
	call $203c			; (8252) make the rom call
	ret				; return

NEVERENDINGSTORY:			; infinite loopin'
	jp NEVERENDINGSTORY		; round and round and round we go...


SETHELPSCREEN:
	ld d,2				; sets register d to 2 (used to tell SETBORDER we want red)
	call SETBORDER
	call CLEARSCREEN		; calls the subroutine CLEARSCREEN
	;call SETMAINBACKGROUND		; calls the subroutine SETMAINBACKGROUND
	call SETHELPTEXT		; sets the help text
	ret

SETMAINSCREEN:				; sets up the main screen
	ld d,1				; sets register d to 1 (used to tell SETBORDER we want blue)
	call SETBORDER			; calls the subroutine SETBORDER
	call CLEARSCREEN		; calls the subroutine CLEARSCREEN
	;call SETMAINBACKGROUND		; calls the subroutine SETMAINBACKGROUND
	call NEWGAMEPLACECHESSMEN
	call SETTEXT			; calls the subroutine SETTEXT
	ret				; return

SETHELPTEXT:				; prints the help screen text
	ld a, 2				; loads 2 into register A
	call $1601			; (5633) 
	ld de, helpstring		; get the infomation to player
	ld bc, eostr-helpstring		; figure the length
	call $203c			; (8252) make the rom call
	ret				; return
end main
EDIT

Ok I figured out what was up - as Seven-FFF pointed out my attributes were all out of whack...

Image
still got to finish the white side pieces
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Crap 0.1 first assembly project

Post by AndyC »

Yeah, Chess has an interesting problem from the point of view of the Speccy display because a white piece either has to have a different image or different attributes from a black piece on the same square. It's a lot easier on machines like the CPC where you can just use four arbitrary colours....
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 »

Oh hell yes, I should have but didn't see the white INK/PAPER thing coming. If you're sticking with a green/white grid you'll need different graphics/colours for the white pieces depending where they land.

I guess this is the fork in the road between having to refund and not! Though an easy get out could be to make it a battle between black and red.

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

Re: Crap 0.1 first assembly project

Post by Nomad »

AndyC wrote: Fri Jan 05, 2018 9:45 pm Yeah, Chess has an interesting problem from the point of view of the Speccy display because a white piece either has to have a different image or different attributes from a black piece on the same square. It's a lot easier on machines like the CPC where you can just use four arbitrary colours....
Yea at the back of my mind there was a nagging doubt about the colours but I dismissed it, then boom. :) Will just have to be black/red.
R-Tape wrote: Fri Jan 05, 2018 10:18 pm Oh hell yes, I should have but didn't see the white INK/PAPER thing coming. If you're sticking with a green/white grid you'll need different graphics/colours for the white pieces depending where they land.

I guess this is the fork in the road between having to refund and not! Though an easy get out could be to make it a battle between black and red.

Image
Yes you are right, Black and red is not so bad choice, I totally forgot about the colour issues with the spectrum until it happened haha. Even back of the magazine advert software needed visible graphics to avoid the dreaded refund request. Can't really do black and white graphics as people would quite rightly complain its not a zx80/zx81.

Red and black seems a good way to proceed. mmmm going to look fabulous against a green square :roll: :lol:
Never mind I think even with a colour combination seemingly selected by a blind person people would still suck up the purchase and persevere with it.

I been trying to make heads or tails of the MACRO command for pasmo but the documentation is not so helpful. Are there any examples on how get the syntax to work? I been throwing , [ ( at it but pasmo is complaining its getting unexpected surprises)

so what I am trying to do is pass a value to the macro..

Code: Select all

 STAMP_SQU  MACRO [CONSTANT]
	ld hl, 22528+CONSTANT
	ld (hl), p2colour_WS
	ld hl, 22528+CONSTANT+1
	ld (hl), p2colour_WS
	ld hl, 22528+CONSTANT+64
	ld (hl), p2colour_WS
	ld hl, 22528+CONSTANT+65
	ld (hl), p2colour_WS
        ENDM
My ancestors are getting restless all this code replication. I suspect its slowing down the program also.
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 remember butting up against pasmo macros too. I think I deleted all my working examples when I abandoned it and moved onto a different assembler.

There's a random example here that threatens to work...

Code: Select all

RESERVE MACRO wSize,IReg
PUSH IReg
LD IReg,-wSize
ADD IReg,SP
LD SP,IReg
ENDM

FREE MACRO wSize,IReg
LD IReg,wSize
ADD IReg,SP
LD SP,IReg
POP IReg
ENDM

...
RESERVE ADDFUNC_Size,IX
...
FREE ADDFUNC_Size,IX
Yours look right except you don't need the square brackets. It's markup to indicate optional parameters, rather than something you type.
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: Sat Jan 06, 2018 1:16 am I remember butting up against pasmo macros too. I think I deleted all my working examples when I abandoned it and moved onto a different assembler.

There's a random example here that threatens to work...

Code: Select all

RESERVE MACRO wSize,IReg
PUSH IReg
LD IReg,-wSize
ADD IReg,SP
LD SP,IReg
ENDM

FREE MACRO wSize,IReg
LD IReg,wSize
ADD IReg,SP
LD SP,IReg
POP IReg
ENDM

...
RESERVE ADDFUNC_Size,IX
...
FREE ADDFUNC_Size,IX
Yours look right except you don't need the square brackets. It's markup to indicate optional parameters, rather than something you type.
Lol - I tried with commas, without brackets, nothing is working. Lol these labour saving/efficiency steps seem to be a huge time sink with little pay off.

Is there an assembler for z80 that is extensively documented and has a less cryptic syntax that is full featured? That runs on linux natively?

Hang on... pasmo is expecting me to RESERVE and FREE those sound like you are priming a one shot operation.. from the stack won't that end up being slower? what's the point of the thing if it can't be used repeatedly. I must be missing the point totally. Ok I can see an edge case where you won't know some values until execution but that seems such a specific problem compared to letting a man have a function be passed values.

There must be an analogy to user functions that receive parameters somewhere...

hmm.. I must be missing something obvious. - EDIT Yes I was being a big dummy.

There is no spoon.
There is no spoon.
There is no spoon.

Lol - I forget that I can just write the subroutine to use either a memory location or a bunch of registers to achieve the result I want. Now I just need to figure out how to make it happen..
Last edited by Nomad on Sat Jan 06, 2018 3:28 am, edited 1 time in total.
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 »

Yes, I've confused you even further, sorry :( FREE and RESERVE aren't anything important, just examples of some dude's macros with parameter syntax that presumably worked for the dude.

I just tried it, and hit the same problems you did. Investigating further...

My answer to all such questions is Zeus :D It has an inbuilt emulator and good macro support, and you can step through your source code. And it does run under Wine. Other brands are available...

Image

Macros aren't really functions, they're expanded out into their full form at assembly time. What appears to be parameters is really hardcoded. For example, if you had this (assuming you got it to work properly!):

Code: Select all

TEST MACRO Foo
ld b, Foo
MEND

TEST 1
TEST 2
TEST 3
the assembler would actually generate

Code: Select all

ld b, 1
ld b, 2
ld b, 3
The illusion of a function is useful to make your code more readable and avoid unnecessary copypaste, but you have to retain a good sense of what code the assembler is actually generating, otherwise you'll run into problems. Another thing Zeus can do do is list out the hex values of the code it's assembling alongside your source code, so you always know what you're generating.

"Real" functions are usually done with call and ret, loading the parameters into registers (or memory addresses, as you said) before you call them. You could rewrite the previous example using a as the parameter:

Code: Select all

ld a, 1
call Test
ld a, 2
call Test
ld a, 3 
call Test
...
Test:
ld b, a
ret
Does that make sense?
Last edited by Seven.FFF on Sat Jan 06, 2018 3:31 am, edited 4 times in total.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
Post Reply