MMBasic for Windows - betas

Author Message


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


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:

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

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
     Poke DataPos data_pos% ' Restore the data pointer.
     Exit Sub
   Print Space$(5 - depth%) Str$(depth%) s$ " ";
   If depth% > 1 Then Print
   mad(depth% - 1)
 Goto my_label
End Sub

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