commit b8e7f09

zzo38  ·  2023-04-25 02:41:45 +0000 UTC
parent 248bd77
Changing some of the extensions.
2 files changed,  +81, -21
M main.c
+52, -14
 1@@ -214,14 +214,8 @@ emulator to the program), ? for parameters that may be input and/or output,
 2   for src_page and dst_page in expanded memory operations.)
 3 
 4 03 device_id uuid% >version ?extra%
 5-  Loads a nonstandard device. The device ID is the starting port number to
 6-  use, which must be nonzero and must be a multiple of sixteen; some
 7-  implementations may impose further restrictions. The UUID is sixteen
 8-  bytes long. The version is zero if not implemented or nonzero if it is
 9-  implemented (the specific value is defined by the specification of that
10-  extension). The extra data depends on the extension, and may be unused
11-  (if it is unknown or unused, then the emulator MUST ignore it and not
12-  make changes to that data).
13+  Loads a nonstandard device, or a nonstandard command for an existing
14+  device or that applies globally; see below section for details.
15 
16 a0 offset%
17   Given a 32-bit offset, seek the currently opened file to the specified
18@@ -242,18 +236,62 @@ a3 >offset%
19   Tell the current offset of the currently opened file; the 32-bit offset
20   will be stored in the expansion command buffer.
21 
22-b_ offset%
23+b_ ?offset%
24   Same as a_ but for the second file.
25 
26 Nonstandard ports of devices are:
27 
28-17
29-  If the high bit is set (by the uxn program), then it will trigger on
30-  EOF; the value of input will be zero and the value of this port will
31-  be 0x80. (The high bit will be preserved by the emulator.)
32-
33 a7/b7
34   In addition to the usual effect (sets the append mode), writing anything
35   to this port (whether or not it is the same value that was previously
36   written) will close the file.
37 
38+
39+=== Extensions ===
40+
41+This describes the nonstandard "03 extensions" command mentioned above.
42+
43+The parts of the command are:
44+
45+* Command code: Always 0x03.
46+
47+* Device number: A command that does not load or override a device into a
48+device slot is zero, otherwise it is a nonzero multiple of sixteen. Some
49+extensions and some implementations may have further restrictions.
50+
51+* UUID: Sixteen bytes, which identifies the extension.
52+
53+* Version: One byte. The emulator writes a nonzero value here (the specific
54+value is defined by the extension) if it is supported in this mode with
55+this device number and other parameters, or zero if it is not implemented.
56+(The uxn program should put zero here by default, so that if running on an
57+emulator that doesn't process the 03 command at all, it will work.)
58+
59+* Extra data: The number of bytes and meaning is defined by the specific
60+extension; this may be read-only, write-only, or some combination. If the
61+extension is not implemented, then the emulator MUST ignore it and MUST NOT
62+attempt to write anything here, and MUST NOT override any devices.
63+
64+
65+=== Implemented extensions ===
66+
67+This section lists the "03 extensions" (see above) that are implemented in
68+this emulator (the -x switch is required, since they use nonstandard
69+expansion commands to activate them).
70+
71+5afdcdfe-e263-11ed-9634-002618745416
72+  The device number must be 0x10. This will enable calling the stdio vector
73+  on EOF; the type will be zero in this case. The version will be 1 (but
74+  this only means that the emulator supports this feature; it does not mean
75+  that stdin is connected to something that actually has a EOF). This
76+  implementation requires the -n switch to be used to support this command.
77+
78+80175132-e263-11ed-b8c9-002618745416
79+  Allows setting separate foreground and background colours. The device
80+  number must be zero, and the version will be 1. The data is eight 16-bit
81+  numbers, for the colours in order background 0 to 3 and then foreground 0
82+  to 3 (although note that foreground 0 is not normally meaningful), with
83+  the high to low nybble of each being red, green, blue, unused (zero).
84+  What happens if you then try to change colours using the colour ports
85+  after doing this, is not specified.
86+
M main.c
+29, -7
 1@@ -222,6 +222,7 @@ static volatile Uint8 timer_expired=0;
 2 static SDL_Surface*screen;
 3 static Uint8 layers;
 4 static Uint8 palet=7;
 5+static Uint8 eof_trigger=0;
 6 
 7 static Sint32*audio_option;
 8 static SDL_AudioSpec audiospec;
 9@@ -851,6 +852,27 @@ static void run_audio(void) {
10   }
11 }
12 
13+static void do_extension_by_uuid(Uint16 addr) {
14+  static const Uint8 uuid_eof[]="\x5A\xFD\xCD\xFE\xE2\x63\x11\xED\x96\x34\x00\x26\x18\x74\x54\x16";
15+  static const Uint8 uuid_8color[]="\x80\x17\x51\x32\xE2\x63\x11\xED\xB8\xC9\x00\x26\x18\x74\x54\x16";
16+  int i;
17+  if(mem[addr+1]==0x10 && !use_screen && !memcmp(mem+addr+2,uuid_eof,16)) {
18+    eof_trigger=1;
19+    mem[addr+18]=1;
20+  } else if(mem[addr+1]==0x00 && use_screen && !memcmp(mem+addr+2,uuid_8color,16)) {
21+    for(i=0;i<8;i++) {
22+      colors[i+070].r=(mem[addr+19+i+i]>>4)*0x11;
23+      colors[i+070].g=(mem[addr+19+i+i]&15)*0x11;
24+      colors[i+070].b=(mem[addr+20+i+i]>>4)*0x11;
25+    }
26+    if(palet==7) {
27+      SDL_SetColors(screen,colors+palet*8,0,8);
28+      picture_changed=1;
29+    }
30+    mem[addr+18]=1;
31+  }
32+}
33+
34 static void system_exp(Device*dev,Uint16 addr) {
35   Uint32 src,dst;
36   Uint16 len;
37@@ -872,6 +894,7 @@ static void system_exp(Device*dev,Uint16 addr) {
38     case 0x03:
39       if(!use_extension) break;
40       mem[addr+18]=0;
41+      do_extension_by_uuid(addr);
42       break;
43   }
44 }
45@@ -1257,8 +1280,8 @@ static int run_screen(void) {
46         run(GET16(device[9].d));
47         break;
48       case SDL_USEREVENT+1:
49-        if(use_extension) device[1].d[7]&=0xF0;
50         device[1].d[2]=e.user.code;
51+        device[1].d[7]=1;
52         run(GET16(device[1].d));
53         break;
54       case SDL_JOYAXISMOTION:
55@@ -1494,11 +1517,11 @@ int main(int argc,char**argv) {
56   if(device[1].d[0] || device[1].d[1]) for(i=optind+1;i<argc;i++) {
57     for(j=0;argv[i][j];j++) {
58       device[1].d[2]=argv[i][j];
59-      device[1].d[7]=(device[1].d[7]&0x80)|0x02;
60+      device[1].d[7]=2;
61       run(GET16(device[1].d));
62     }
63     device[1].d[2]='\n';
64-    device[1].d[7]=(device[1].d[7]&0x80)|(i==argc-1?0x04:0x03);
65+    device[1].d[7]=(i==argc-1?4:3);
66     run(GET16(device[1].d));
67   }
68   if(use_screen) {
69@@ -1512,14 +1535,13 @@ int main(int argc,char**argv) {
70   } else if(audio_option) {
71     run_audio();
72   } else {
73-    device[1].d[7]=(device[1].d[7]&0x80)|0x01;
74+    device[1].d[7]=1;
75     while((device[1].d[0] || device[1].d[1]) && ((i=getchar())>=0)) {
76       device[1].d[2]=i;
77       run(GET16(device[1].d));
78     }
79-    if(use_extension && (device[1].d[7]&0x80)) {
80-      device[1].d[2]=0;
81-      device[1].d[7]=(device[1].d[7]&0x80)|0x00;
82+    if(eof_trigger) {
83+      device[1].d[2]=device[1].d[7]=0;
84       run(GET16(device[1].d));
85     }
86   }