205 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			205 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
 | 
						|
GetDoubledBottomNibble:
 | 
						|
  push bc
 | 
						|
  swap b
 | 
						|
  jp GetDoubledNibbleInner
 | 
						|
GetDoubledTopNibble:
 | 
						|
  push bc
 | 
						|
  jp GetDoubledNibbleInner
 | 
						|
GetDoubledNibbleInner:
 | 
						|
  ; b holds a byte of tile data
 | 
						|
  ; this returns the first byte of the doubled tile data
 | 
						|
  
 | 
						|
  ld a, b
 | 
						|
  and a, %10000000 ; a contains a0000000
 | 
						|
  ld c, a
 | 
						|
  rrca 
 | 
						|
  or a, c ; a now contains aa000000
 | 
						|
  ld [vBuildingByte], a ; vBuildingByte has aa000000
 | 
						|
  
 | 
						|
  ld a, b
 | 
						|
  and a, %01000000 ; a has 0b000000
 | 
						|
  rrca ; a has 00b00000
 | 
						|
  ld c, a ; c has 00b00000
 | 
						|
  rrca ; a has 000b0000
 | 
						|
  or a, c
 | 
						|
  ld c, a ; c has 00bb0000
 | 
						|
  ld a, [vBuildingByte] 
 | 
						|
  or a, c 
 | 
						|
  ld [vBuildingByte], a ; vBuildingBye has aabb0000
 | 
						|
  
 | 
						|
  
 | 
						|
  ld a, b
 | 
						|
  and a, %00100000 ; 00c00000
 | 
						|
  rrca ; 000c0000
 | 
						|
  rrca ; 0000c000
 | 
						|
  ld c, a 
 | 
						|
  rrca ; 00000c00
 | 
						|
  or a, c ; 0000cc00
 | 
						|
  ld c, a 
 | 
						|
  ld a, [vBuildingByte]
 | 
						|
  or a, c
 | 
						|
  ld [vBuildingByte], a ; vBuildingByte has aabbcc00
 | 
						|
  
 | 
						|
  ld a, b 
 | 
						|
  and a, %00010000
 | 
						|
  rrca
 | 
						|
  rrca
 | 
						|
  rrca
 | 
						|
  ld c, a 
 | 
						|
  rrca
 | 
						|
  or a, c
 | 
						|
  ld c, a 
 | 
						|
  ld a, [vBuildingByte]
 | 
						|
  or a, c 
 | 
						|
  ld [vBuildingByte], a  ; vBuilldingByte now has aabbccdd!
 | 
						|
  pop bc
 | 
						|
  ret ;so does a.
 | 
						|
 | 
						|
WriteBottomHalfDoubledTile:
 | 
						|
; this draws the bottom half of a tile pointed at by hl into [de]
 | 
						|
  ld bc, 8
 | 
						|
  add hl, bc
 | 
						|
WriteTopHalfDoubledTile:
 | 
						|
; this draws the top half of a tile into [de]
 | 
						|
; both of these functions take hl, pointing to tile data, and write four 
 | 
						|
; lines of it, doubled, to DE
 | 
						|
; in other words we draw the left half of the top of a tile into [de]
 | 
						|
; then we draw the right half of the top of a tile into [de]
 | 
						|
; ending with writing 32 bytes to [de], or two tiles' worth.
 | 
						|
  push hl
 | 
						|
  call DoubleLeftSideOfLineOfTile
 | 
						|
  call DoubleLeftSideOfLineOfTile
 | 
						|
  call DoubleLeftSideOfLineOfTile
 | 
						|
  call DoubleLeftSideOfLineOfTile
 | 
						|
  
 | 
						|
  pop hl
 | 
						|
  call DoubleRightSideOfLineOfTile
 | 
						|
  call DoubleRightSideOfLineOfTile
 | 
						|
  call DoubleRightSideOfLineOfTile
 | 
						|
  call DoubleRightSideOfLineOfTile
 | 
						|
  
 | 
						|
  ld bc, 8
 | 
						|
  add hl, bc
 | 
						|
  ret
 | 
						|
  
 | 
						|
DoubleLeftSideOfLineOfTile:
 | 
						|
  ; hl points to tile data.
 | 
						|
  ; de points to a buffer we want to write into
 | 
						|
  ; this will increment hl twice to point at the next line
 | 
						|
  ; and de four times, writing the doubled left side
 | 
						|
  ld b, [hl]
 | 
						|
  call GetDoubledTopNibble
 | 
						|
  ld [de], a ; write that to a
 | 
						|
  inc hl ; now we're poinitinig at the second bitplane.
 | 
						|
  inc de 
 | 
						|
  ld b, [hl]
 | 
						|
  call GetDoubledTopNibble
 | 
						|
  ld [de], a ; write that to a 
 | 
						|
  
 | 
						|
  ; now we want to double that line. so fetch the two bytes we just wrote
 | 
						|
  ; and write them again.
 | 
						|
  dec de
 | 
						|
  ld a, [de]
 | 
						|
  inc de
 | 
						|
  inc de
 | 
						|
  ld [de], a 
 | 
						|
  dec de
 | 
						|
  ld a, [de]
 | 
						|
  inc de
 | 
						|
  inc de
 | 
						|
  ld [de], a 
 | 
						|
  
 | 
						|
  inc de
 | 
						|
  inc hl
 | 
						|
  
 | 
						|
  ret
 | 
						|
DoubleRightSideOfLineOfTile:
 | 
						|
  ; hl points to tile data.
 | 
						|
  ; de points to a buffer we want to write into
 | 
						|
  ; this will increment hl twice to point at the next line
 | 
						|
  ; and de four times, writing the doubled left side
 | 
						|
  ld b, [hl]
 | 
						|
  call GetDoubledBottomNibble
 | 
						|
  ld [de], a ; write that to a
 | 
						|
  inc hl ; now we're poinitinig at the second bitplane.
 | 
						|
  inc de 
 | 
						|
  ld b, [hl]
 | 
						|
  call GetDoubledBottomNibble
 | 
						|
  ld [de], a ; write that to a 
 | 
						|
  
 | 
						|
  ; now we want to double that line. so fetch the two bytes we just wrote
 | 
						|
  ; and write them again.
 | 
						|
  dec de
 | 
						|
  ld a, [de]
 | 
						|
  inc de
 | 
						|
  inc de
 | 
						|
  ld [de], a 
 | 
						|
  dec de
 | 
						|
  ld a, [de]
 | 
						|
  inc de
 | 
						|
  inc de
 | 
						|
  ld [de], a 
 | 
						|
  
 | 
						|
  inc de
 | 
						|
  inc hl
 | 
						|
  
 | 
						|
  ret
 | 
						|
 | 
						|
 | 
						|
 | 
						|
DrawByte: ; accepts [hl] as the number to write, de as location to write tile IDs to
 | 
						|
; writes tile IDs for one byte (two nibbles) from [hl] into [de]
 | 
						|
  ld b, 0 
 | 
						|
  
 | 
						|
  push hl
 | 
						|
  ld a, [hl]
 | 
						|
  swap a 
 | 
						|
  and a, $0F
 | 
						|
  ld c, a 
 | 
						|
  ld hl, .lowerHex
 | 
						|
  add hl, bc
 | 
						|
  ld a, [hl]
 | 
						|
  ld [de], a 
 | 
						|
  inc de
 | 
						|
  
 | 
						|
  pop hl
 | 
						|
  ld a, [hl]
 | 
						|
  and a, $0F
 | 
						|
  ld c, a 
 | 
						|
  ld hl, .lowerHex
 | 
						|
  add hl, bc
 | 
						|
  ld a, [hl]
 | 
						|
  ld [de], a 
 | 
						|
  
 | 
						|
  ret
 | 
						|
  
 | 
						|
.lowerHex ; tile IDs for hex values. 
 | 
						|
  ; 0, 1, 2, 3, 
 | 
						|
  db $a0, $a1, $a2, $a3 
 | 
						|
  ; 4, 5, 6, 7,
 | 
						|
  db $a4, $a5, $a6, $a7
 | 
						|
  ; 8, 9
 | 
						|
  db $a8, $a9
 | 
						|
  ; a, b, c, d, e, f
 | 
						|
  db $d1, $d2, $d3, $d4, $d5, $d6
 | 
						|
 | 
						|
 | 
						|
 | 
						|
FindTileData: ; give it a=index into some tiles, hl=what to start from
 | 
						|
  ; returns hl = start of thatt tile data
 | 
						|
  ld b, h
 | 
						|
  ld c, l 
 | 
						|
  
 | 
						|
  ld h, 0 
 | 
						|
  ld l, a 
 | 
						|
  add hl, hl ; hl * 2
 | 
						|
  add hl, hl ; hl * 4
 | 
						|
  add hl, hl ; hl * 8
 | 
						|
  add hl, hl ; hl * 16
 | 
						|
  
 | 
						|
  add hl, bc 
 | 
						|
  
 | 
						|
  ret
 | 
						|
 | 
						|
  
 |