Merge branch 'master' into newplasma

This commit is contained in:
Martin Haye 2017-08-04 08:48:34 -07:00
commit 01491a5038
6 changed files with 130 additions and 46 deletions

View File

@ -71,6 +71,9 @@ class A2PackPartitions
def tiles = [:] // tile id to tile.buf
def tileSets = [:] // tileset name to tileset.num, tileset.buf
def avatars = [:] // avatar tile name to tile num (within the special tileset)
def compassTiles = [:] // compass direction (north, east, south, west) to tile num (within global tileset)
def clockTiles = [:] // clock time (e.g. 12:00, 1:30) to tile num (within global tileset)
def lampTiles = [] // animated series of lamp tiles
def textures = [:] // img name to img.num, img.buf
def frames = [:] // img name to img.num, img.buf
def portraits = [:] // img name to img.num, img.buf
@ -838,16 +841,36 @@ class A2PackPartitions
tiles[imgEl.@id] = buf
}
/** Identify the avatars and number them */
def numberAvatars(dataIn)
/** Identify the avatars and other global tiles, and number them */
def numberGlobalTiles(dataIn)
{
def nFound = 0
dataIn.tile.sort{it.@name.toLowerCase()}.each { tile ->
def name = tile.@name
if (name.toLowerCase().contains("avatar"))
avatars[name.toLowerCase().trim().replaceAll(/\s*-\s*[23][dD]\s*/, "")] = nFound++
def tileNum = 0
dataIn.tile.sort{(it.@category + it.@name).toLowerCase()}.each { tile ->
def lname = tile.@name.toLowerCase().trim().replaceAll(/\s*-\s*[23][dD]\s*/, "")
def cat = tile.@category.toLowerCase().trim()
if (cat == "avatar")
avatars[lname] = tileNum++
else if (cat == "compass") {
for (def dir : ['north', 'east', 'south', 'west']) {
if (lname.contains(dir)) {
compassTiles[dir] = tileNum++
break
}
}
}
else if (cat == "clock") {
for (def time : ['12:00', '1:30', '3:00', '4:30', '6:00', '7:30', '9:00', '10:30']) {
if (lname.contains(time)) {
clockTiles[time] = tileNum++
break
}
}
}
else if (cat == "lamp") {
lampTiles << tileNum++
}
}
assert nFound >= 1 : "Need at least one 'Avatar' tile."
assert avatars.size() >= 1 : "Need at least one tile in 'Avatar' category."
}
/** Pack the global tiles, like the player avatar, into their own tile set. */
@ -861,13 +884,13 @@ class A2PackPartitions
def buf = ByteBuffer.allocate(50000)
// Add each special tile to the set
dataIn.tile.sort{it.@name.toLowerCase()}.each { tile ->
dataIn.tile.sort{(it.@category + it.@name).toLowerCase()}.each { tile ->
def name = tile.@name
def id = tile.@id
def data = tiles[id]
if (name.toLowerCase().contains("avatar")) {
def cat = tile.@category.toLowerCase().trim()
if (cat == "avatar" || cat == "compass" || cat == "clock" || cat == "lamp") {
def num = tileMap.size()
avatars[name.toLowerCase().trim().replaceAll(/\s*-\s*[23][dD]\s*/, "")] = num
tileIds.add(id)
tileMap[id] = num
data.flip() // crazy stuff to append one buffer to another
@ -2127,7 +2150,7 @@ class A2PackPartitions
}
// Pack the global tile set before other tile sets (contains the player avatar, etc.)
numberAvatars(dataIn)
numberGlobalTiles(dataIn)
packGlobalTileSet(dataIn)
// Divvy up the images by category
@ -3065,6 +3088,9 @@ end
def oldSep = System.getProperty("line.separator")
System.setProperty("line.separator", "\n")
// We have to identify and number the global tiles before generating the image header.
numberGlobalTiles(dataIn)
// Translate image names to constants and symbol names
new File("build/src/plasma").mkdirs()
new File("build/src/plasma/gen_images.plh.new").withWriter { out ->
@ -3091,13 +3117,22 @@ end
}
}
out.println "const PF_LAST = $frameNum"
out.println ""
for (def dir : ["north", "east", "south", "west"])
out.println "const COMPASS_${dir.toUpperCase()} = ${compassTiles.containsKey(dir) ? compassTiles[dir] : -1}"
out.println ""
for (def time : ['12:00', '1:30', '3:00', '4:30', '6:00', '7:30', '9:00', '10:30'])
out.println "const CLOCK_${time.replace(':', '_')} = ${clockTiles.containsKey(time) ? clockTiles[time] : -1}"
out.println ""
out.println "const BASE_AVATAR = ${avatars.values()[0]}"
}
replaceIfDiff("build/src/plasma/gen_images.plh")
// Before we can generate global script code, we need to identify and number
// all the maps. Same with avatars.
// Before we can generate global script code, we need to identify and number all the maps.
numberMaps(dataIn)
numberAvatars(dataIn)
// Form the translation from item name to function name (and ditto
// for players)

View File

@ -1703,21 +1703,30 @@ NxtScLn LDY pTmp+1
INY
INY
INY
CPY #$40
BCC .ok2
TYA
EOR pTmp+1 ; compare to old value
AND #$20 ; still on same hi-res page?
BEQ .ok ; yes, done
TYA ; no, move back to next block on pg
SEC
SBC #$20 ; carry already set
TAY
LDA pTmp
EOR #$80
STA pTmp
BMI .ok
INY
CPY #$24
BCC .ok
LDY #$20
TYA
AND #4
BEQ .ok
DEY
DEY
DEY
DEY
LDA pTmp
ADC #$27 ; carry was set, so actually adding $28
.ok STA pTmp
.ok2 STY pTmp+1
STA pTmp
.ok STY pTmp+1
RTS
HgrTbHi !byte $20,$24,$28,$2C,$30,$34,$38,$3C

View File

@ -13,6 +13,7 @@ include "globalDefs.plh"
include "playtype.plh"
include "diskops.plh"
include "party.plh"
include "gen_images.plh"
include "gen_modules.plh"
include "gen_players.plh"
@ -290,7 +291,7 @@ end
def newGame()#0
word playersModule, newGameModule, partyModule
initHeap(0) // initially empty heap
global->b_curAvatar = 0
global->b_curAvatar = BASE_AVATAR
global=>w_combatPauseCt = DEFAULT_COMBAT_PAUSE_CT
mmgr(START_LOAD, 1) // players module and new game module both in partition 1
playersModule = mmgr(QUEUE_LOAD, MOD_GEN_PLAYERS<<8 | RES_TYPE_MODULE)

View File

@ -94,6 +94,7 @@ byte allowZoneInit = FALSE
word curEngine = NULL
word pIntimate = NULL
word pResourceIndex = NULL
word pGlobalTileset = NULL
byte curMapPartition = 0
export word pGodModule = NULL
@ -484,8 +485,8 @@ export asm finishString(isPlural)#1
end
///////////////////////////////////////////////////////////////////////////////////////////////////
asm blit(srcData, dstScreenPtr, nLines, lineSize)#0
+asmPlasmNoRet 4
asm blit(isAux, srcData, dstScreenPtr, nLines, lineSize)#0
+asmPlasmNoRet 5
; Save line size
sta ysav
@ -506,7 +507,11 @@ asm blit(srcData, dstScreenPtr, nLines, lineSize)#0
lda evalStkH+3,x
sta tmp+1
; Create the following subroutine, used to copy pixels from aux to main:
; Save aux/main flag
lda evalStkL+4,x
lsr ; to carry bit
bcc +
; If reading from aux, create the following subroutine:
; 0010- 8D 03 C0 STA $C003
; 0013- B1 02 LDA ($02),Y
; 0015- 91 04 STA ($04),Y
@ -539,12 +544,21 @@ asm blit(srcData, dstScreenPtr, nLines, lineSize)#0
sta $19
lda #$60
sta $1D
pla ; line count
+ pla ; get line count
tax
- ldy ysav ; byte count minus 1. There are 18 bytes per line
--
ldy ysav ; get byte count
dey
jsr $10 ; copy pixel bytes
bcc +
jsr $10 ; copy pixel bytes (aux version)
bcs ++
+
- lda (tmp),y
sta (pTmp),y
dey
bpl -
++
php
lda tmp ; advance to next row of data
clc
adc ysav
@ -552,8 +566,9 @@ asm blit(srcData, dstScreenPtr, nLines, lineSize)#0
bcc +
inc tmp+1
+ jsr NextScreenLine ; and next screen line
plp
dex
bne - ; Loop until we've done all rows.
bne -- ; Loop until we've done all rows.
rts
end
@ -1642,6 +1657,21 @@ export def loadMainFrameImg()#0
fin
end
///////////////////////////////////////////////////////////////////////////////////////////////////
def showCompassDir(dir)#0
word tile
word screenAdr
if dir < 2; tile = COMPASS_EAST
elsif dir < 6; tile = COMPASS_SOUTH
elsif dir < 10; tile = COMPASS_WEST
elsif dir < 14; tile = COMPASS_NORTH
else tile = COMPASS_EAST; fin
tile = pGlobalTileset + (tile<<5)
screenAdr = getScreenLine(168)+4
blit(0, tile, screenAdr, 16, 2)
blit(0, tile, screenAdr+$2000, 16, 2)
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Load code and data, set up everything to display a 2D or 3D map
def initMap(x, y, dir)#0
@ -1675,6 +1705,7 @@ def initMap(x, y, dir)#0
curMapPartition = lookupResourcePart(mapIs3D+1, mapNum)
mmgr(START_LOAD, curMapPartition)
pMap = mmgr(QUEUE_LOAD, mapNum<<8 | (RES_TYPE_2D_MAP+mapIs3D))
pGlobalTileset = mmgr(QUEUE_LOAD, 1<<8 | RES_TYPE_TILESET) // even in 3d, need tiles for compass/clock/etc.
mmgr(FINISH_LOAD, 0)
// Clear all the windows to the background color (hi-bit set)
@ -1704,6 +1735,7 @@ def initMap(x, y, dir)#0
setAvatar(global->b_curAvatar)
doRender()
fin
if mapIs3D; showCompassDir(dir); fin
// Assume there might be animations until we learn otherwise
anyAnims = TRUE // for now; might get cleared if we discover otherwise on advance
@ -1804,10 +1836,12 @@ def moveForward()#1
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Adjust player's direction plus or minus n increments
// Adjust player's direction plus or minus n increments; returns new dir
def adjustDir(n)#1
setDir((getDir() + n) & 15)
return 0
byte dir
dir = (getDir() + n) & 15
setDir(dir)
return dir
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -1836,14 +1870,16 @@ end
// Turn left (3D mode)
def rotateLeft()#1
needRender = TRUE
return adjustDir(-1)
showCompassDir(adjustDir(-1))
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
// Rotate to the right (3D mode)
def rotateRight()#1
needRender = TRUE
return adjustDir(1)
showCompassDir(adjustDir(1))
return 0
end
///////////////////////////////////////////////////////////////////////////////////////////////////
@ -2083,13 +2119,13 @@ def showAnimFrame()#0
if curPortrait
// Blit portrait to the appropriate area on the screen
if frameLoaded == 3 // 3D-mode frame? Note: don't check mapIs3D, because we might be in an engine
blit(curPortrait + 2, getScreenLine(24)+2, 128, 18) // start at 3rd text line
blit(1, curPortrait + 2, getScreenLine(24)+2, 128, 18) // start at 3rd text line
else
blit(curPortrait + 2, getScreenLine(32)+2, 128, 18) // start at 4th text line
blit(1, curPortrait + 2, getScreenLine(32)+2, 128, 18) // start at 4th text line
fin
needRender = FALSE // suppress display of map for this frame
elsif curFullscreenImg
blit(curFullscreenImg + 2, getScreenLine(0), 192, 40) // the +2 is to skip anim hdr offset
blit(1, curFullscreenImg + 2, getScreenLine(0), 192, 40) // the +2 is to skip anim hdr offset
needRender = FALSE // suppress display of map for this frame
elsif mapIs3D
render()

View File

@ -37,7 +37,7 @@ const BIGWIN_HEIGHT = BIGWIN_BOTTOM - BIGWIN_TOP
const RES_TYPE_CODE = 1
const RES_TYPE_2D_MAP = 2
const RES_TYPE_3D_MAP = 3
const RES_TYPE_TILE = 4
const RES_TYPE_TILESET = 4
const RES_TYPE_TEXTURE = 5
const RES_TYPE_SCREEN = 6
const RES_TYPE_FONT = 7

View File

@ -853,16 +853,19 @@ ROW_OFFSET = 3
STA AVATAR_SECTION
LDA DRAW_SECTION + 1
STA AVATAR_SECTION + 1
LDA #0
STA .tsadd+1
LDY #5 ; 32 bytes per tile
LDA PLAYER_TILE ; get tile number
ASL ; 32 bytes per tile
ASL
ASL
ASL
ASL
- ASL
ROL .tsadd+1
DEY
BNE -
CLC
ADC GLOBAL_TILESET_LOC
TAY
LDA GLOBAL_TILESET_LOC+1
ADC #0
.tsadd ADC #0 ; self-modified above
BNE .store_src ; always taken
.notAvatar
LDA DRAW_SECTION+1