Loading new data and discarding old data

Post programming questions related to the CPC Here!
Post Reply
Kitsune Mifune
Posts: 28
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Loading new data and discarding old data

Post by Kitsune Mifune » Mon Nov 11, 2019 10:04 am

I think at this stage I need to learn how to separate my program into parts which are loaded separately. At the moment, the title screen, character screen, and actual game are all just part of the same big program, and everything is just lobbed into RAM on compile. They branch off to each other fine, but memory is becoming an issue.

So, if say, I leave the title screen by pushing fire, I don't need those logo graphics or whatever hanging around in RAM anymore, but I don't know how to flush them out.

I thought about using an 'ifdef' or something so that the actual code for the other parts wouldn't be assembled until they were told to be, but again it's getting rid of the old stuff.

Is it just a simple case of overwriting in the same memory location that was specified in the 'org', or specifying a new block?

The code below is for my title screen (please excuse any noob inefficiency). When 's' is pushed it goes to the setup section of the next screen before its own loop, but it's really just a branch off to a section of an already included and compiled external .asm file (the "jp CHARSELECT_INITIALISE" part of the TITLE_PUSHSTART function). It doesn't actually load any new data at that point or getting rid of unneeded stuff, it just jumps there.

I'm just wondering if I'll maybe have to get in to stuff like disk loading etc.?

As always, many thanks for any wisdom imparted.

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
					      ;; TITLE SCREEN ;;
					      ;;;;;;;;;;;;;;;;;;

	org &0700

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom variables for THIS SCREEN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	X_POS		dw 0		; General purpose X-Position container
	Y_POS		dw 0		; General purpose Y-Position container
	L_XPOS		dw &34		; LEFT hand side of logo's X-Position container	
	L_YPOS		dw &C6		; LEFT hand side of logo's Y-Position container		
	R_XPOS		dw &57		; RIGHT hand side of logo's X-Position container	
	R_YPOS		dw &C6		; RIGHT hand side of logo's Y-Position container	
	LR		dw 0		; Draw decider (Decides which side of logo to draw)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
;; SET UP SCREEN & INITIALIASE STUFF ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TITLE_INITIALISE:	

;	ld a,1				; Load Palette choice value (Not needed ATM)
;	ld (WHICHPALETTE),a		; Load value into variable memory location  (Not needed ATM)
	call SCREENSETUP		; Call the screen setup script
	ld a,4				; Tells text script what to print
	ld (WHICHTEXT),a

	call PRINT_CHARNAME		; Print text to the screen	; All static and just called once (no need to be in loop...I think?)
	call DRAWLEFT			; Draw Left side of Logo	;
	call DRAWRIGHT			; Draw Right side of Logo	;
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TITLE SCREEN LOOP ;;
;;;;;;;;;;;;;;;;;;;;;;;

TITLE_MAINLOOP:				; TITLESCREEN MAIN LOOP START
	call TITLE_PUSHSTART
jr TITLE_MAINLOOP			; TITLESCREEN MAIN LOOP END

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SET WHICH SIDE OF LOGO TO DRAW ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DRAWLEFT:				; Draw Left hand side of logo
	ld a,1
	ld (LR),a			; Let draw routine what side it is drawing (1 = LEFT, 2 = RIGHT)
	ld de,(L_XPOS)			; Load left hand side's X Position into 'a'
	ld (X_POS),de			; Transfer from 'a' to general purpose X position variable
	ld de,(L_YPOS)			; Load left hand side's Y Position into 'a'	
	ld (Y_POS),de			; Transfer from 'a' to general purpose Y position variable
	jr DRAWTITLE			; Send to draw routine

DRAWRIGHT:				; Draw right hand side of logo
	ld a,2				; 	
	ld (LR),a			; 	
	ld de,(R_XPOS)			; 	
	ld (X_POS),de			; 	** REPEAT AS ABOVE **
	ld de,(R_YPOS)			; 	
	ld (Y_POS),de			; 
	jr DRAWTITLE			; 	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DRAW GRAPHICS CODE ;;
;;;;;;;;;;;;;;;;;;;;;;;;

DRAWTITLE:					; Main label to call for all drawing
	push de

		ld a,(X_POS)			; Load X-POSITION
		ld b,a
		ld a,(Y_POS)			; LOAD Y-POSITION
		ld c,a
		call GetScreenPos		; New plotting code
;		call SPRITEPOS_IN_PIXELS	; &BC1D Firmware (HA! Don't need you anymore, fucker!!!)
	pop de

	WHICHSIDE:				; What Graphics data to fetch and look at
		D_LEFT:				; Draw LEFT side of Logo
			ld a,(LR)
			cp 1
			jr nz, D_RIGHT	
			xor a
			ld de,TITLELEFT		
			jr WHICHSIDE_END
		D_RIGHT:			; Draw RIGHT side of Logo
			ld a,(LR)
			cp 2
			jr nz, WHICHSIDE_END
			xor a	
			ld de,TITLERIGHT	; What Graphics data to fetch and look at
	WHICHSIDE_END:
			ld a,174		; Height (LINES)	
			ld b,a
	TITLE_Spritenextline:
		push hl
			ld a,35			; Width (BYTES)
			ld c,a			; Bytes per line
		TITLE_Spritenextbyte:
				ld a,(de)				
				ld (hl),a	
	
				inc de
				inc hl

				dec c
				jr nz,TITLE_Spritenextbyte
		pop hl
		call GetNextLine		; Scr Next Line
		;call SCREEN_NEXTLINE		; Fuck you too!!!
	djnz TITLE_Spritenextline		
;RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PUSH START TO GO TO CHARACTER SELECT SCREEN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TITLE_PUSHSTART:
		ld a,60			; ASCII code for 's'
		call READ_KEY	
		jr z, SKIPFIRE
		jp CHARSELECT_INITIALISE
	SKIPFIRE:
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SCREEN SETUP & PALETTE DEFINITION ;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

SCREENSETUP:
	
	ld a,0
	call MODE_0					; Screen mode 0
	call CLS					; Clear the screen
	ld b,16						; Colour Number
	ld bc,&0000					; Value of the border colour (&0000 = &0101 = blue)
        call SCREENBORDER				; &bc38 sets the border colour	
	call SET_PALETTE				; New universal way of setting palette

;	ld a, (WHICHPALETTE)				; Palette Select  (Not needed ATM)
;	ld b,a

;	TITLEPAL:					
;		cp 1				
;		jp nz, CHARSELECTPAL
;		call TITLESCREEN_PALETTE
;		jr PALETTE_DONE
;	CHARSELECTPAL:
;		cp 2
;		jp nz, GAMEPAL
;		call CHARSELECT_PALETTE
;		jr PALETTE_DONE
;	GAMEPAL:
;		cp 3
;		jp nz, TITLEPAL
;		call GAME_PALETTE
;	PALETTE_DONE
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EXTERNAL ASM FILES ;;
;;;;;;;;;;;;;;;;;;;;;;;;

ASM_DATAFILES: 		read "C:\Amstrad\ASM\GAME\ASM_DATAFILES.ASM"	; Variables/code for other screens etc.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; TITLE SCREEN GRAPHICS DATA ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TITLELEFT: 		incbin "C:\Amstrad\Graphics\Titlescreen\Title Transp LEFT.RAW"
TITLERIGHT:		incbin "C:\Amstrad\Graphics\Titlescreen\Title Transp RIGHT.RAW"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Programming: 90% failures, 10% victories, and 100% hair loss!

User avatar
akuyou
Posts: 438
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Loading new data and discarding old data

Post by akuyou » Wed Nov 13, 2019 9:56 am

If possible it would be best to limit your game to a single 64k diskload to save yourself some sanity, but if that's not possible, then things are going to get more complex...

You can clear an area of memory with the command below - it uses LDIR to copy zeros over an area:

Code: Select all

Cldir:			;Fill BC+1 Bytes from DE with Zero
	ld a,0
CldirAlt:
	ld h,d
	ld l,e
	ld (hl),a
	inc de
	ldir
	ret
Regarding Disk ops, I've added a new sample to my sources.7z... it's called 'CPC_DiskTest.asm'
https://www.chibiakumas.com/z80/sources.7z

This is designed to work with the disk image provided with that 7z... it has a simple(ish) example of a Load and Save command... so beware, as it will create a file on whatever disk is inserted in winape...

You're probably going to have to start thinking about bank-switching too soon I suspect.
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Kitsune Mifune
Posts: 28
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Re: Loading new data and discarding old data

Post by Kitsune Mifune » Wed Nov 13, 2019 11:39 am

Thanks for the info.

Yeah, I've hit that stage where I'll have to really think about organising stuff. My code is in bits right now after some major tearing down and reworking, so this would be the best time.

Cheers for the files, I'll have a look tonight.
Programming: 90% failures, 10% victories, and 100% hair loss!

Post Reply

Return to “Amstrad CPC Assembly Programming”