Sun Mar 20, 2016 11:09 pm
Mon Mar 21, 2016 5:43 am
Mon Mar 21, 2016 8:01 am
deeph wrote:Nice, can't way to look at your code
Are you using your asm sprite routine ? Because yesterday I tested the tillemapper I coded with it (well, a little enhanced, since I'm making a game with it), and I got strange sounds from the speakers and strange behavior when the player is either facing up or right with animated tiles. I can't understand why, I didn't experienced this with the classic sprite routine...
So do you plan on making your own game (RPG) ? With my game (a pokemon-clone), I'm actually at 14,128 bytes (43%) of PROGMEM and 1,237 bytes of RAM, which include the tilemapper, player handling, 3 maps, events handling (warps/dialogs...), and a start for the battle engine. I still don't know if I'll be able to put everything I need in the PROGMEM. I can show you the code eventually.
Mon Mar 21, 2016 12:09 pm
#include <SPI.h>
#include <Gamebuino.h>
#include <EEPROM.h>
#include <GB_Fat.h>
Gamebuino gb;
#define TILEMAP_WIDTH 12
#define TILEMAP_HEIGHT 8
byte camX = 0;
byte camY = 0;
byte sprites[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
byte sprite_player[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55};
byte tilemap[TILEMAP_WIDTH * TILEMAP_HEIGHT];
GB_Fat sd;
GB_File file;
#include "graphics.h"
class Player {
byte x=8,y=8;
public:
void update(){
if(gb.buttons.repeat(BTN_RIGHT,0)){
x++;
}
if(gb.buttons.repeat(BTN_LEFT,0)){
x--;
}
if(gb.buttons.repeat(BTN_UP,0)){
y--;
}
if(gb.buttons.repeat(BTN_DOWN,0)){
y++;
}
sprite_xor(sprite_player,x,y);
moveCam(x - (LCDWIDTH / 2), y - (LCDHEIGHT / 2));
}
};
void setup() {
// put your setup code here, to run once:
gb.begin();
gb.setFrameRate(40);
gb.display.clear();
gb.display.println(F("loading card..."));
gb.display.update();
if(sd.init(gb.display.getBuffer(),SPISPEED_VERYHIGH)!=NO_ERROR){
gb.display.clear();
gb.display.print(F("SD card not found."));
gb.display.update();
while(1);
}
gb.display.clear();
gb.display.println(F("seaching for file card..."));
gb.display.update();
file = sd.open("DATA.DAT",gb.display.getBuffer());
if(!file.exists()){
gb.display.clear();
gb.display.print(F("Couldn't open file."));
gb.display.update();
while(1);
}
gb.display.clear();
gb.display.println(F("card found"));
gb.display.update();
file.read(tilemap,0,96);
/*
byte buffer[11];
buffer[10] = '\0';
file = sd.open("TEST.TXT",gb.display.getBuffer());
if(!file.exists()){
gb.display.clear();
gb.display.print(F("Couldn't open file."));
gb.display.update();
while(1);
}
file.read(buffer,32768 - 5,10);
gb.display.clear();
gb.display.println(reinterpret_cast<const char*>(buffer));
gb.display.update();
while(1);*/
}
Player player;
void loop() {
// put your main code here, to run repeatedly:
if(gb.update()){
drawTilemap();
player.update();
}
}
void sprite_xor(byte data[], byte xx, byte yy){
int8_t x = xx - camX;
int8_t y = yy - camY;
uint8_t* buf = (((y+8)&0xF8)>>1) * 21 + x + gb.display.getBuffer();
asm volatile(
"mov R20,%[y]\n\t"
"ldi R17,7\n\t"
"add R20,R17\n\t"
"brmi End\n\t"
"cpi %[y],48\n\t"
"brpl End\n\t"
"inc R20\n\t"
"ldi R16,8\n\t"
"andi R20,7\n\t"
"cpi R20,0\n\t"
"breq LoopAligned\n"
"LoopStart:\n\t"
"tst %[x]\n\t"
"brmi LoopSkip\n\t"
"cpi %[x],84\n\t"
"brcc LoopSkip\n\t"
"ld R17,Z\n\t"
"eor R18,R18\n\t"
"mov R19,R20\n\t"
"clc\n\t"
"LoopShift:\n\t" // carry is still reset from the cpi instruction or from the dec
"rol R17\n\t"
"rol R18\n\t"
"dec R19\n\t"
"brne LoopShift\n\t"
"tst %[y]\n\t"
"brmi LoopSkipPart\n\t"
"ld R19,X\n\t"
"eor R19,R17\n\t"
"st X,R19\n\t"
"LoopSkipPart:\n\t"
"cpi %[y],40\n\t"
"brpl LoopSkip\n\t"
"ld R19,Y\n\t"
"eor R19,R18\n\t"
"st Y,R19\n\t"
"LoopSkip:\n\t"
"eor R18,R18\n\t"
"ldi R19,1\n\t"
"add R26,R19\n\t" // INC DOESN'T CHANGE CARRY!
"adc R27,R18\n\t"
"add R28,R19\n\t"
"adc R29,R18\n\t"
"add R30,R19\n\t"
"adc R31,R18\n\t"
"inc %[x]\n\t"
"dec R16\n\t"
"brne LoopStart\n\t"
"rjmp End\n"
"LoopAligned:\n\t"
"tst %[x]\n\t"
"brmi LoopAlignSkip\n\t"
"cpi %[x],84\n\t"
"brcc LoopAlignSkip\n\t"
"ld R17,Z\n\t"
"ld R18,X\n\t"
"eor R18,R17\n\t"
"st X,R18\n\t"
"LoopAlignSkip:\n\t"
"ldi R18,1\n\t"
"add R26,R18\n\t"
"adc R27,R20\n\t"
"add R30,R18\n\t"
"adc R31,R20\n\t"
"inc %[x]\n\t"
"dec R16\n\t"
"brne LoopAligned\n"
"End:\n\t"
::"x" (buf - 84),"y" (buf),"z" (data),[y] "r" (y),[x] "r" (x):"r16","r17","r18","r19","r20");
}
void drawTilemap(){
int8_t startDdx = (-camX) / 8;
int8_t startDdy = (-camY) / 8;
int8_t maxDdx = (LCDWIDTH + 8 - 1 + camX) / 8;
int8_t maxDdy = (LCDHEIGHT + 8 - 1 + camY) / 8;
if(TILEMAP_WIDTH < maxDdx){
maxDdx = TILEMAP_WIDTH;
}
if(TILEMAP_HEIGHT < maxDdy){
maxDdy = TILEMAP_HEIGHT;
}
if(startDdx < 0){
startDdx = 0;
}
if(startDdy < 0){
startDdy = 0;
}
for(byte ddy = startDdy;ddy < maxDdy;ddy++){
for(byte ddx = startDdx;ddx < maxDdx;ddx++){
sprite_xor(sprites + tilemap[ddy*TILEMAP_WIDTH + ddx]*8,ddx*8,ddy*8);
}
}
}
void moveCam(int8_t x,int8_t y){
if(x < 0){
camX = 0;
}else if(x > (TILEMAP_WIDTH*8) - LCDWIDTH){
camX = (TILEMAP_WIDTH*8) - LCDWIDTH;
}else{
camX = x;
}
if(y < 0){
camY = 0;
}else if(y > (TILEMAP_HEIGHT*8) - LCDHEIGHT){
camY = (TILEMAP_HEIGHT*8) - LCDHEIGHT;
}else{
camY = y;
}
}
Mon Mar 21, 2016 5:09 pm
Sorunome wrote:Do you have its map data being read off of the sd card, though? Because if so that is very impressive!
Sorunome wrote:As for the sprite routine, the asm one I presented doesn't have clipping (it assumes the sprite is fully on screen). Lukily I found somewhere in that same thread a version with full clipping, the lower clipping was broken, though, so I fixed that. The sound was generated on your end as you overwrote random ram areas, probably those used for sound.
Sorunome wrote:As for rpg-making, as mentioned I do not intend to push this very far if people wouldn't help me.
Mon Mar 21, 2016 6:03 pm
Well, if you run out of PROGMEM you might want to switch to something like this, then ^.^deeph wrote:Sorunome wrote:Do you have its map data being read off of the sd card, though? Because if so that is very impressive!
No, I'm reading maps from the PROGMEM, but I don't foresee to have big ones for my game, so it's the best solution I guess.
Done!deeph wrote:Sorunome wrote:As for the sprite routine, the asm one I presented doesn't have clipping (it assumes the sprite is fully on screen). Lukily I found somewhere in that same thread a version with full clipping, the lower clipping was broken, though, so I fixed that. The sound was generated on your end as you overwrote random ram areas, probably those used for sound.
Nice, thank you for fixing it, but I think that you should update your post then
deeph wrote:Sorunome wrote:As for rpg-making, as mentioned I do not intend to push this very far if people wouldn't help me.
I'd like to make a game with you, and could reuse some of the tools/code I made for my own project Why not start a thread ?
I'll look more in details your custom library and clean my own code to post it when I have the time.
Tue Mar 22, 2016 8:57 pm
Gamebuino #1:
2GB sd card:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 34631636 microseconds
147841.68 bytes per second
144.38 kilobytes per second
128MB card #1:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 31541664 microseconds
162324.98 bytes per second
158.52 kilobytes per second
128MB card #2:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 32531620 microseconds
157385.34 bytes per second
153.70 kilobytes per second
Gamebuino #2:
2GB sd card:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 34719360 microseconds
147468.15 bytes per second
144.01 kilobytes per second
128MB card #1:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 31538812 microseconds
162339.65 bytes per second
158.53 kilobytes per second
128MB card #2:
Starting speed benchmark....
10000 times (5120000 bytes ) read in 32530728 microseconds
157389.65 bytes per second
153.70 kilobytes per second