MMBasic for Windows - betas


Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3782
Posted: 11:03am 03 Mar 2022      

Peter,

I offer this for your consideration regarding manipulating the global data pointer. It's been "mangled" due to the changes I've been making to modularise the MMBasic code for MMB4L, but I'm sure you can figure out how to apply it to your implementation:

/** PEEK(DATAPOS) */
static void peek_datapos(int argc, char **argv, char *p) {
   if (argc != 1) ERROR_SYNTAX;
   uint64_t data_pos = ((NextDataLine - ProgMemory) << 32) + NextData;
   g_integer_rtn = data_pos;
   g_rtn_type = T_INT;
}

/** POKE DATAPOS data_pos% */
static void poke_datapos(int argc, char** argv, char *p) {
   if (argc != 1) ERROR_ARGUMENT_COUNT;
   uint64_t data_pos = (uint64_t) getinteger(p);
   NextDataLine = ProgMemory + (data_pos >> 32);
   NextData = data_pos & 0xFFFFFFFF;
}


And example MMBasic:
Option Base 0
Option Default None
Option Explicit On

Restore my_data
mad(5)
End

Sub mad(depth%)
 If depth% = 0 Then Exit Sub
 Local data_pos% = Peek(DataPos) ' Cache the data pointer.
 Local s$
 Restore my_data
 my_label: ' There seems to be an issue with using recursion and DO or FOR loops ?
           ' Might be MMB4L specific.
   Read s$
   If s$ = "" Then
     Print
     Poke DataPos data_pos% ' Restore the data pointer.
     Exit Sub
   EndIf
   Print Space$(5 - depth%) Str$(depth%) s$ " ";
   If depth% > 1 Then Print
   mad(depth% - 1)
 Goto my_label
End Sub

my_data:
Data "A", "B", "C", "D", "E", ""


EDIT: And before anyone starts to "have a go at me" for diverging from "standard" BASIC, we had an extremely flexible way of providing stateless data access by using CSUBs as binary data blobs, until Peter decided it was a hack and wasn't going to be supported by MMB4W  .
Edited 2022-03-03 21:18 by thwill