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 »

To be honest today was not so fast progress, but what progress there was was ok. Player input is now a thing, in a basic way. But at least the program now looks at 23560, compares it to a bunch of different keys and then does a bunch of stuff. ala the menu.

That said, what didn't go so well today was... tommygunn refused to work just kept throwing exceptions all over the shop when i ran it with wine, zxpaintbrush was also freaking out. So I think perhaps my install of wine is borked. (trump voice) Sad.

I am thinking of just getting some poverty desktop to put a copy of windows on just to run these dev apps as most of the spectrum development programs seem to be windows based...

So got some stuff on the screen, got my texts going where I want them, the graphics are a bit of an enigma but I finally figured out what I was doing wrong with the udgs (not treating them like a string/char). I need to spend more time with the sprite side of things and get a handle on that. Then everything will be more smooth.

Thing that went much easier than expected was the musical side of the project, lol that was done in under a min (and it shows - but then a crap game needs crap music :D)
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Its the 1st of January, So I have 364 days to complete this crap game. Things are looking good.
1. SevenUp works fine, so its now much less of a hassle doing specky graphics. That was the first good news of the day.
2. Audio is already ready to go into the game. Sound effects got done this morning. (farts and sweeps)
3. Player movement is done.
4. boundary checking is done.
5. Pointer is done.
6. plus other minor stuff.

So things left that need to be fixed - I thought just do a basic background this time, I will do a fully tiled master work some other game. But at the moment it would be nice to get this done and move on. With that in mind, the layout of the main game screen is pretty easy - just print the coordinates for the board along the grid, and have the player moves along the right hand side, a basic menu system and a help screen and besides the animation of pieces, and some kind of print routine for the game history its done.

My understanding is back in the day some commercial crap spectrum titles were written and sent out to customers in 28 days. Would be fun to see if I can complete this in 28 days. I used to think those kinds of turn around times were unbelievable but now I can see how it could be done - especially if a guy knew what he was doing and had a template already/old code from other projects he could re use. Doing something impressive though would have still taken time.

Happy new year party people!
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 2: (363 days left..)

Got the pawn sprite done. got a bunch of libraries for z80 assembly on the spectrum so while i feel its a little bit of a short cut, it greatly improves my noob chances of getting something finished that looks ok. I think even a crap game has some standards...

1. It should be better than a basic type-in from the magazines of the time. In other words for this challenge to be complete it should have stuff that my 6 year old self would have sat down and said "damn I can't do that in basic..." Something that could have realistically been sold for a few quid in the back of a magazine at the start of the spectrum era. The use case is - guy pays 5 pounds and is instantly disappointed but not enough to demand a refund.

2. No copy-pasta, I need to actually understand what the program is doing. This is a learning exercise first and foremost so I can't just use a game creator program. Not saying I have to write everything in a cave, but it should be understood first before being used. I agonised over using the libraries because of this but its not on the same level. I can always learn how to do the fancy sprite stuff next time.

With that in mind today was pretty productive, figuring out what can be done with the libraries, and then that will leave me tomorrow with a list of stuff I still have outstanding. Will get the library demos working tonight and go from there.

Going to finish the Jonathan Cauldwell guide, that was extremely useful. http://s3.spanglefish.com/s/22323/docum ... mes1.0.zip

Also well worth a look http://sgate.emt.bme.hu/patai/publicati ... index.html for general Z80 assembly.

The main library I have been looking at was by Sebastian Mihai. libzx. http://sebastianmihai.com/main.php?t=13 ... y-language
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Crap 0.1 first assembly project

Post by dfzx »

Nomad wrote: Tue Jan 02, 2018 9:04 am The use case is - guy pays 5 pounds and is instantly disappointed but not enough to demand a refund.
:lol: :lol: :lol: ROFLMAO! :lol: :lol: :lol:

Keep going, and keep commentating. I love threads like this.
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.
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: Crap 0.1 first assembly project

Post by Wall_Axe »

if yer usin linux you can use pasmo i think, or some other assembler
make files are useful
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Wall_Axe wrote: Tue Jan 02, 2018 1:54 pm if yer usin linux you can use pasmo i think, or some other assembler
make files are useful
Pasmo is what I am using at the moment, I like how you can generate the tap files with it. :)
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Crap 0.1 first assembly project

Post by Nomad »

Day 3: (362 days left)

Got all arty-farty with screen painter :lol: The idea was to have a main background that was:

1. Garish to the point of migraine inducing, colour theory should be actively avoided.
2. I was lazy and figured the board is not going to move so might as well plonk it on the background.

Image
Gents, I think everyone is in agreement :D

Now the only thing I have to do is put this bad boy into the crap program... At the moment I am looking at libzx and the way that the background is loaded there is pretty straight forward however the background is not in the same format as what you get from the tools when I save as bin or as a code.

Its expecting

Code: Select all

 db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
but that's not what the screens save as :(

I frankly don't trust myself to not make a mistake manually editing the whole bin file. Will try and figure out a way to automate this. But if someone can point out where I am going wrong or how i can just load the bin of the background into the program that would be fabulous.

Faffing around with the background loader and screen paint was not the only thing project related that got done today. In the spirit of the challenge. I figured the type of deviant that would create such crap and actually try and sell it to the unsuspecting public would want to maximise the profit potential. Therefore a port to other platforms would be desirable. But to keep within the spirit of the challenge it should be a lazy port with no optimisations just the bare minimum to get it working on the Amstrad CPC, and MSX. (The enterprise was a little bit thin on the documentation side - I figured that would be to difficult to do even a lazy port to that bad boy.)

So yea, in light of this - I got the CPC and MSX emulators installed, pasmo should be fine with both these. There was enough documentation and enough info online to be able to do a lazy port. For this title its very basic functionality. Its a matter of getting the memory map for the target, the keyboard routine, and the graphics display. (Like a true lazy/cash grab I might slash the audio component on the ports) Bidabang badaboom two new markets to be disappointed.

Boxart - because these things have to oversell/promise and critically under deliver.
I was thinking something along the lines of..
Image
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Crap 0.1 first assembly project

Post by Seven.FFF »

ZX-Paintbrush will save the graphics in this format, with the Export function. Was it you that was saying in another post you were on linux, and couldn't get ZX-Paintrush to work under Wine?

However - looking at the libzx code, it's just expecting 6944 bytes of a SCREEN$. Most assemblers have a binary include directive. In pasmo for example, it would be

Code: Select all

incbin "myscreen.scr"
http://pasmo.speccy.org/pasmodoc.html#dirincbin

Just replace the entire block of db directives with this, or the equivalent in your assembler.
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 03, 2018 4:43 pm ZX-Paintbrush will save the graphics in this format, with the Export function. Was it you that was saying in another post you were on linux, and couldn't get ZX-Paintrush to work under Wine?

However - looking at the libzx code, it's just expecting 6944 bytes of a SCREEN$. Most assemblers have a binary include directive. In pasmo for example, it would be

Code: Select all

incbin "myscreen.scr"
http://pasmo.speccy.org/pasmodoc.html#dirincbin

Just replace the entire block of db directives with this, or the equivalent in your assembler.
:D Thank you very much, this worked a treat!
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 »

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 :)
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 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: 1388
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.
Post Reply