Skip to content

Commit

Permalink
Started on 32x32 tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Robson committed Feb 7, 2024
1 parent b3208a9 commit 9d0b703
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
43 changes: 22 additions & 21 deletions basic/test.bsc
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
renumber
cls
list
' "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
' "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
' "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
print "abcdefghi"
a
b
c
d
e
f
g
h
i
j
k
l
m
n
cls:gload "graphics.gfx"
mem = alloc(8*6+3):rect solid ink 4 from 0,0 to 319,239
poke mem,1:poke mem+1,8:poke mem+2,6
for y = 0 to 5
base = (y & 1) * $F0
for x = 0 to 7
poke x+y*8+mem+3,base+x
next
next
tilemap mem,0,0
call draw(10,10)
end
call draw(114,183)
call draw(250,-8)
call draw(-11,109)
end


proc draw(x,y)
s = 1
tiledraw x,y dim s to x+8*s*16,y+6*s*16
endproc
5 changes: 2 additions & 3 deletions documents/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ General
Larger Additions
----------------

- Complete 32x32 tiles (scaled)

- Reference Parameters

- 32x32 tiles (scaled)

- Merge CPM65 PR

- Cat Wildcard (post Merge ?)

- Serial uploading
- save to storage option.


- Sprites
- something like AMAL - write spec document, probably bytecode

Expand Down
1 change: 1 addition & 0 deletions documents/release/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,5 @@ Changes
IMP: Insert and Delete work, Backspace works properly.
IMP: Added DELETE command
IMP: Added RENUMBER command
BRK: The size is now passed via DIM in the TILEDRAW not TILEMAP.

Binary file modified documents/release/api.odt
Binary file not shown.
1 change: 1 addition & 0 deletions firmware/common/include/interface/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void GFXPlotPixel(struct GraphicsMode *gMode,int x,int y);
void GFXPlotPixelChecked(struct GraphicsMode *gMode,int x,int y);
void GFXEllipse(struct GraphicsMode *gMode,int x1,int y1,int x2,int y2,int useSolidFill);
int GFXFindImage(int type,int id);
uint8_t GFXGetDrawSize(void);

#endif

Expand Down
10 changes: 10 additions & 0 deletions firmware/common/sources/interface/gfxcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ void GFXSetDefaults(uint8_t *cmd) {
flipBits = cmd[8];
}

// ***************************************************************************************
//
// Accessor for draw size
//
// ***************************************************************************************

uint8_t GFXGetDrawSize(void) {
return drawSize;
}

// ***************************************************************************************
//
// Draw a pixel
Expand Down
29 changes: 19 additions & 10 deletions firmware/common/sources/interface/tilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ static uint8_t *gDraw; // Draw from here.
static uint8_t *tilePtr; // Tile data from here.
static uint8_t *tilePixels; // Tile pixel data.
static uint16_t yTile; // Tracking tile draw position.
static uint8_t tileSize; // Tile Size = 16 or 32
static uint8_t tileShift; // Tile shift to divide (4 or 5)

static void TMRRenderTileLine(uint8_t count);
static void TMRenderTileLineStart(uint8_t count);
Expand All @@ -45,11 +47,17 @@ void TMPSelectTileMap(uint8_t *data,uint16_t xOffset,uint16_t yOffset) {
// ***************************************************************************************

uint8_t TMPDrawTileMap(uint8_t *data) {

int xPos = xTilePos,yPos = yTilePos;

tileSize = 16;tileShift = 4; // Work out size and shift
if (GFXGetDrawSize() == 2) {
tileSize = 32;tileShift = 5;
}

if (mapData == NULL) return 1; // No map specified.
if (xPos < 0 || yPos < 0 || // Invalid draw position.
xPos >= width * 16 || yPos >= height * 16) return 1;
xPos >= width * tileSize || yPos >= height * tileSize) return 1;

int16_t x1 = data[4]+(data[5] << 8); // Parameters.
int16_t y1 = data[6]+(data[7] << 8);
Expand All @@ -58,7 +66,7 @@ uint8_t TMPDrawTileMap(uint8_t *data) {

xWindow = (x1 < x2) ? x1 : x2;yWindow = (y1 < y2) ? y1 : y2; // Work out drawing window
wWindow = abs(x1-x2);hWindow = abs(y1-y2);
if (wWindow < 16) return 1; // Reject this special case.
if (wWindow < tileSize) return 1; // Reject this special case.

if (xWindow < 0) { // Adjust for off left
xPos += abs(xWindow);
Expand All @@ -84,30 +92,30 @@ uint8_t TMPDrawTileMap(uint8_t *data) {
int xLeader,xBlock16,xTrailer;

int todo = wWindow; // Pixels horizontally
if (xPos+wWindow >= width * 16) todo = width*16-xPos; // Trim to right side
xLeader = (-xPos & 15); // Pixels to display to first whole tile.
xBlock16 = (todo - xLeader) / 16; // Number of whole tiles to display
xTrailer = todo - xLeader - xBlock16 * 16; // Pixels to display to edge.
if (xPos+wWindow >= width * tileSize) todo = width*tileSize-xPos; // Trim to right side
xLeader = (-xPos & (tileSize-1)); // Pixels to display to first whole tile.
xBlock16 = (todo - xLeader) / tileSize; // Number of whole tiles to display
xTrailer = todo - xLeader - xBlock16 * tileSize; // Pixels to display to edge.

gDraw = gMode.graphicsMemory + x + yWindow * gMode.xGSize; // Start drawing here.

// printf("TD:%d,%d %d,%d\n",xWindow,yWindow,wWindow,hWindow);
// printf("%d %d %d\n",xLeader,xBlock16,xTrailer);

while (lineCount > 0 && yTile < height * 16) { // Until complete or off tile map
tilePtr = mapData + 3 + (yTile >> 4) * width + (xPos >> 4); // Tile data comes from here.
while (lineCount > 0 && yTile < height * tileSize) { // Until complete or off tile map
tilePtr = mapData + 3 + (yTile>>tileShift)*width+(xPos>>tileShift); // Tile data comes from here.
uint8_t *gStart = gDraw; // Start of drawing.
if (y >= 0 && y <= gMode.yGSize) {
if (xLeader != 0) TMRenderTileLineStart(xLeader); // Do the first pixels.
for (int i = 0;i < xBlock16;i++) TMRRenderTileLine(16); // Render complete 16 pixel tiles.
for (int i = 0;i < xBlock16;i++) TMRRenderTileLine(tileSize); // Render complete 16 pixel tiles.
if (xTrailer != 0) TMRRenderTileLine(xTrailer); // Do the last pixels.
if (todo != wWindow) TMROutputBackground(wWindow-todo); // Any following blanks
}
y++;lineCount--; // Next line.
gDraw = gStart + gMode.xGSize; // Down on screen
yTile++; // Next tile position
}
while (lineCount-- > 0) {
while (lineCount-- > 0) { // Blank the bottom unused area to sprites only.
for (uint16_t i = 0;i < wWindow;i++) {
gDraw[i] &= 0xF0;
}
Expand Down Expand Up @@ -227,5 +235,6 @@ static void TMRenderTileLineStart(uint8_t count) {
// Date Revision
// ==== ========
// 28-01-24 Amended to allow tilemaps to overlap windows.
// 07-02-24 Started conversion to allow 32x32 tiles (scaled)
//
// ***************************************************************************************

0 comments on commit 9d0b703

Please sign in to comment.