memory revamp described, endianness checked

This commit is contained in:
Luxferre
2022-08-13 08:46:25 +03:00
parent df9d9b7cbc
commit 03cf5e95fe
2 changed files with 44 additions and 18 deletions
+21
View File
@@ -34,6 +34,9 @@
#define cputc(c) (putchar(c))
#endif
/* also, do our best to ensure short-packed value storage in our virtual RAM */
#pragma pack(2)
/* Definitions section */
#define EQUI_VER "0.0.1"
@@ -312,6 +315,12 @@ ushort crc16(const uchar* data_p, uchar length) {
return crc;
}
/* Short endianness conversion helper */
ushort tobig(ushort val) {
return (val>>8)|((val&255)<<8);
}
/* Persistent operation handler */
ushort persistOp(FILE *pfd, ushort maddr, ushort dataLen, ushort adl, ushort adh, uchar isWrite) {
@@ -587,6 +596,9 @@ void equi_main_loop() {
int main(int argc, char* argv[]) {
uchar instr, bc, smode = 0;
/* detect host endianness */
int host_islittle = 1;
host_islittle = (*((char *)&host_islittle) == 1) ? 1 : 0;
/* _attempt_ to disable buffering for char input/output */
#if !defined __CC65__ && !defined __TINYC__
setvbuf(stdin, NULL, _IONBF, 0);
@@ -622,6 +634,15 @@ int main(int argc, char* argv[]) {
ram.clt_start, ram.gpd_start - ram.clt_start, ram.gpd_start, ram.cmd_start - ram.gpd_start, ram.cmd_start, ram.cmd_size);
}
/* now, if necessary, convert the values that could be read by the program to big-endian */
if(host_islittle) {
ram.stack_size = tobig(ram.stack_size);
ram.clt_start = tobig(ram.clt_start);
ram.gpd_start = tobig(ram.gpd_start);
ram.cmd_start = tobig(ram.cmd_start);
ram.cmd_size = tobig(ram.cmd_size);
}
while(1) { /* Now, we're in the command mode loop */
instr = cgetc(); /* Fetch the next instruction from the keyboard/stdin */
if(instr == 0xFFU || instr == 0U) /* exit on zero byte */