Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:56 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMBasic for Windows - support for Xbox and DualShock 4 controllers

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 05:47pm 23 Dec 2023
Copy link to clipboard 
Print this post

V5.07.03b24


MMBasic.zip


New commands

GAMEPAD ON [interrupt] [,MASK] ' mask specifies which buttons should trigger an interrupt - defaults to all
GAMEPAD OFF
GAMEPAD VIBRATE n' (n=1 to 100)
GAMEPAD STOP 'Stops vibration

NB: the vibrate commands appear to be coded correctly but don't work on my cheap second-hand DualShock4. The code including vibrate isn't tested on a XBox controller which is supposed to be supported but I don't have one.
After the GAMEPAD ON command the first button pressed on the controller activates the system and will report that the controller is connected if all is well. The command can be issued at the command line

NB: The gamepad must be connected to the computer when MMBasic is started

New Function

GAMEPAD(func)

func is the same as the PicoMite and CMM2 i.e. LX, LY, RX, RY for the joysticks and L and R for the analogue buttons. B returns the digital buttons as a bitmap identical to the Wii Classic on the CMM2 and PicoMite. See the example code below
gamepad on myint
Pause 1000
Do
Loop
Sub myint
Static integer l%=0
m%=1
a%=gamepad(b)
t%=l% Xor a%
If t% And m% Then
  If a% And m% Then : Print "R_ON":Else : Print "R_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Start_ON":Else : Print "Start_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Home_ON":Else : Print "Home_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Select_ON":Else : Print "Select_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "L_ON":Else : Print "L_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "DOWN_ON":Else : Print "DOWN_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "RIGHT_ON":Else : Print "RIGHT_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "UP_ON":Else : Print "UP_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "LEFT_ON":Else : Print "LEFT_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "ZR_ON":Else : Print "ZR_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "X_ON":Else : Print "X_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "A_ON":Else : Print "A_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "Y_ON":Else : Print "Y_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "B_ON":Else : Print "B_OFF":EndIf
EndIf
Inc m%,m%
If t% And m% Then
  If a% And m% Then : Print "ZL_ON":Else : Print "ZL_OFF":EndIf
EndIf
l%=a%
End Sub


Edited 2023-12-24 04:17 by matherp
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 07:12pm 23 Dec 2023
Copy link to clipboard 
Print this post

This is so cool matherp, thank you

I have an Xbox gamepad, but first I need to check if this feature will work on wine. I'll let you know
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 04:26am 24 Dec 2023
Copy link to clipboard 
Print this post

matherp

I have tested the new version on Wine 6 (the default version from the Mint repos), and it failed with the following error:

0024:err:module:import_dll Loading library XINPUTUAP.dll

I updated the Wine to version 8, the last stable one, and everything worked perfectly. I also tested the analog sticks and they worked fine as well.

I'm using an Xbox gamepad connected to the USB port.
Edited 2023-12-24 14:35 by LeoNicolas
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 04:56am 24 Dec 2023
Copy link to clipboard 
Print this post

Unfortunately, running Knightmare on this MMB4W version ends in a crash. I don't know if the Wine implementation of the direct input is not stable enough.


Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x6dd5c860).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
EIP:6dd5c860 ESP:6e6bf430 EBP:6dd61588 EFLAGS:00010283(  R- --  I S - - -C)
EAX:00010008 EBX:00000000 ECX:00000000 EDX:00000008
ESI:00000000 EDI:00000000
Stack dump:
0x6e6bf430:  29280000 00000000 6dd61588 6dd5c6c7
0x6e6bf440:  6dd656e0 283dcd14 29383ad0 6ab2f0be
0x6e6bf450:  29383ad0 6dd64a44 00000020 00000000
0x6e6bf460:  00000000 292841c8 6dd61588 6dd52022
0x6e6bf470:  6dd61588 00000000 00000000 6e6bf4b8
0x6e6bf480:  29284178 00000000 0000001d 29383aa0
Backtrace:
=>0 0x6dd5c860 get_value+0x70(table=6DD61588, row=0, column=0, val=6E6BF4B8) [Z:\usr\src\packages\BUILD\dlls\wbemprox\table.c:133] in wbemprox (0x6dd61588)
 1 0x6dd52022 get_propval+0xd2(view=292841C8, index=0, name=L"DeviceID", ret=6E6BF5A0, type=0x000000000, flavor=0x000000000) [Z:\usr\src\packages\BUILD\dlls\wbemprox\query.c:1192] in wbemprox (0x6dd61588)
 2 0x6dd4b510 class_object_Get+0x150(iface=<couldn't compute location>, wszName=<couldn't compute location>, lFlags=<couldn't compute location>, pVal=<couldn't compute location>, pType=<couldn't compute location>, plFlavor=<couldn't compute location>) [Z:\usr\src\packages\BUILD\dlls\wbemprox\class.c:410] in wbemprox (0x6e6bf548)
 3 0x004495df in mmbasic_input (+0x495df) (0x6e6bf61c)
 4 0x00449d86 in mmbasic_input (+0x49d86) (0x6e6bf668)
 5 0x61fc2370 enum_devices_wtoa_callback+0x50(instance_w=<couldn't compute location>, data=<couldn't compute location>) [Z:\usr\src\packages\BUILD\dlls\dinput\ansi.c:726] in dinput8 (0x6e6bf8e8)
 6 0x61fc9edc in dinput8 (+0x9edc) (0x6e6bf908)
 7 0x61fcc98c dinput8_EnumDevices+0x14c(iface=2928437C, type=0x4, callback=61FC2320, context=6E6BFDE8, flags=0) [Z:\usr\src\packages\BUILD\dlls\dinput\dinput_main.c:602] in dinput8 (0x6e6bfdb8)
 8 0x61fc183f dinput8_a_EnumDevices+0x4f(iface_a=<couldn't compute location>, type=<couldn't compute location>, callback=<couldn't compute location>, ref=<couldn't compute location>, flags=<couldn't compute location>) [Z:\usr\src\packages\BUILD\dlls\dinput\ansi.c:738] in dinput8 (0x6e6bfe08)
 9 0x00449d34 in mmbasic_input (+0x49d34) (0x6e6bfec8)
 10 0x00450808 in mmbasic_input (+0x50808) (0x6e6bfee8)
 11 0x6ab2fcd3 _beginthreadex_trampoline+0x53(arg=<couldn't compute location>) [Z:\usr\src\packages\BUILD\dlls\msvcrt\thread.c:200] in ucrtbase (0x6e6bff28)
 12 0x7b629ee0 in kernel32 (+0x29ee0) (0x6e6bff48)
 13 0x7bc5c6e7 in ntdll (+0x5c6e7) (0x6e6bff5c)
 14 0x7bc5cef0 RtlCreateUserThread(entry=6AB2FC80, arg=29283898) [Z:\usr\src\packages\BUILD\dlls\ntdll\thread.c:306] in ntdll (0x6e6bffec)
0x6dd5c860 get_value+0x70 [Z:\usr\src\packages\BUILD\dlls\wbemprox\table.c:133] in wbemprox: movl 0x0(%esi),%eax
Unable to access file 'Z:\usr\src\packages\BUILD\dlls\wbemprox\table.c'
Modules:
Module Address Debug info Name (151 modules)
PE 00370000-0037e000 Deferred        xinputuap
PE 003a0000-003b5000 Deferred        vcruntime140
PE 00400000-281a6000 Export          mmbasic_input
PE 285b0000-28a28000 Deferred        ole32
PE 28a30000-28c43000 Deferred        rpcrt4
PE 28c50000-28cb2000 Deferred        msacm32
PE 29640000-296c4000 Deferred        winex11
PE 49240000-4a5d6000 Deferred        wined3d
ELF 5a5e4000-61fc0000 Deferred        libllvm-15.so.1
PE 61fc0000-620b3000 Dwarf-4         dinput8
PE 62500000-6290a000 Deferred        oleaut32
PE 62c40000-62cb6000 Deferred        concrt140
PE 63e40000-63ebb000 Deferred        winepulse
PE 64180000-64221000 Deferred        winspool
PE 643c0000-64449000 Deferred        ws2_32
PE 646c0000-64746000 Deferred        iphlpapi
PE 64a80000-64ad8000 Deferred        win32u
PE 65680000-658fc000 Deferred        msvcrt
PE 66080000-66179000 Deferred        shlwapi
PE 66640000-6665b000 Deferred        version
PE 667c0000-66806000 Deferred        shcore
PE 66fc0000-66fe4000 Deferred        compstui
PE 67500000-67553000 Deferred        imm32
PE 67bc0000-68043000 Deferred        comctl32
PE 684c0000-6860d000 Deferred        combase
PE 68880000-68d6a000 Deferred        user32
PE 69000000-69266000 Deferred        gdiplus
PE 69840000-6993b000 Deferred        advapi32
PE 6aac0000-6ad9c000 Dwarf-4         ucrtbase
PE 6aec0000-6b06f000 Deferred        setupapi
PE 6bbc0000-6bc57000 Deferred        sechost
ELF 6c1f7000-6c286000 Deferred        libgmp.so.10
ELF 6c286000-6c2d0000 Deferred        libhogweed.so.6
ELF 6c2d0000-6c31a000 Deferred        libnettle.so.8
ELF 6c31a000-6c4c5000 Deferred        libunistring.so.2
ELF 6c4c5000-6c622000 Deferred        libp11-kit.so.0
ELF 6c622000-6c850000 Deferred        libgnutls.so.30
PE 6c850000-6c971000 Deferred        dxgi
PE 6c980000-6cc57000 Deferred        msvcp140
ELF 6cc92000-6cd70000 Deferred        libkrb5.so.3
PE 6da80000-6dc9f000 Deferred        gdi32
ELF 6dce4000-6dd40000 Deferred        libgssapi_krb5.so.2
PE 6dd40000-6de6a000 Dwarf-4         wbemprox
ELF 6ed34000-6ede0000 Deferred        libcups.so.2
PE 6f240000-6f3bc000 Deferred        winmm
ELF 6f71b000-6f820000 Deferred        libgcrypt.so.20
PE 704c0000-704dc000 Deferred        dwmapi
ELF 704dd000-70500000 Deferred        libidn2.so.0
ELF 7060e000-70621000 Deferred        libresolv.so.2
ELF 70621000-70653000 Deferred        libk5crypto.so.3
ELF 70653000-706e0000 Deferred        libvorbisenc.so.2
PE 70d80000-70e20000 Deferred        uxtheme
ELF 70e20000-70e37000 Deferred        libtasn1.so.6
PE 70e50000-70e6b000 Deferred        nsi
PE 71080000-710a8000 Deferred        hid
ELF 710aa000-710c0000 Deferred        libavahi-client.so.3
PE 710c0000-710fe000 Deferred        dnsapi
PE 71400000-720af000 Deferred        shell32
ELF 76b77000-78795000 Deferred        libicudata.so.70
ELF 78795000-7a800000 Deferred        iris_dri.so
PE 7a800000-7acc1000 Deferred        opengl32
ELF 7acc3000-7acd2000 Deferred        libkrb5support.so.0
ELF 7acd2000-7ad31000 Deferred        libopus.so.0
ELF 7ad31000-7ae00000 Deferred        libsystemd.so.0
PE 7b000000-7b52c000 Deferred        kernelbase
ELF 7b53a000-7b565000 Deferred        libgpg-error.so.0
ELF 7b565000-7b600000 Deferred        libsndfile.so.1
PE 7b600000-7b759000 Dwarf-4         kernel32
ELF 7b76f000-7b800000 Deferred        libpulsecommon-15.99.so
PE 7bc00000-7bebc000 Dwarf-4         ntdll
ELF 7bebe000-7bec6000 Deferred        libkeyutils.so.1
ELF 7bec6000-7becc000 Deferred        libcom_err.so.2
ELF 7bedc000-7bf00000 Deferred        liblz4.so.1
ELF 7c400000-7c40f000 Deferred        libavahi-common.so.3
ELF 7c40f000-7c41a000 Deferred        libcap.so.2
ELF 7c41a000-7c425000 Deferred        libogg.so.0
ELF 7cc26000-7ce2c000 Deferred        libicuuc.so.70
ELF 7ce2c000-7d000000 Deferred        libxml2.so.2
ELF 7d000000-7d005000 Deferred        <wine-loader>
ELF 7d005000-7d031000 Deferred        libvorbis.so.0
ELF 7d031000-7d06d000 Deferred        libflac.so.8
ELF 7d06d000-7d083000 Deferred        libapparmor.so.1
ELF 7d083000-7d08b000 Deferred        libasyncns.so.0
ELF 7d406000-7d40c000 Deferred        winspool.so
ELF 7d40c000-7d46b000 Deferred        libdbus-1.so.3
ELF 7d46b000-7d4cb000 Deferred        libpulse.so.0
ELF 7d4cb000-7d4d0000 Deferred        dnsapi.so
ELF 7d4e4000-7d4f9000 Deferred        winepulse.so
ELF 7d67b000-7d6a7000 Deferred        liblzma.so.5
ELF 7d6a7000-7d6b4000 Deferred        libpciaccess.so.0
ELF 7d6b4000-7d6e0000 Deferred        libtinfo.so.6
ELF 7d6e0000-7d719000 Deferred        libedit.so.2
ELF 7d719000-7d725000 Deferred        libffi.so.8
ELF 7d725000-7d72e000 Deferred        libatomic.so.1
ELF 7d72e000-7d755000 Deferred        libgcc_s.so.1
ELF 7d755000-7d77f000 Deferred        libdrm_intel.so.1
ELF 7d77f000-7d789000 Deferred        libdrm_nouveau.so.2
ELF 7d789000-7d796000 Deferred        libdrm_amdgpu.so.1
ELF 7d796000-7d7b4000 Deferred        libelf.so.1
ELF 7d7b4000-7d7c3000 Deferred        libdrm_radeon.so.1
ELF 7d7c3000-7d892000 Deferred        libzstd.so.1
ELF 7d8ab000-7d8bf000 Deferred        libxcb-randr.so.0
ELF 7d8bf000-7d8de000 Deferred        libxcb-glx.so.0
ELF 7d8de000-7d908000 Deferred        libglapi.so.0
ELF 7d908000-7d983000 Deferred        libglx_mesa.so.0
ELF 7d983000-7da00000 Deferred        libgldispatch.so.0
ELF 7df03000-7df0e000 Deferred        libxcb-xfixes.so.0
ELF 7df0e000-7df27000 Deferred        libdrm.so.2
ELF 7df7f000-7df88000 Deferred        libxcb-sync.so.1
ELF 7df88000-7df8d000 Deferred        libxcb-present.so.0
ELF 7df8d000-7df93000 Deferred        libxcb-dri3.so.0
ELF 7df93000-7e000000 Deferred        libgl.so.1
ELF 7e100000-7e13c000 Deferred        libglx.so.0
ELF 7e13d000-7e14e000 Deferred        libsensors.so.5
ELF 7e155000-7e1f7000 Deferred        opengl32.so
ELF 7e23d000-7e245000 Deferred        libxfixes.so.3
ELF 7e245000-7e252000 Deferred        libxcursor.so.1
ELF 7e252000-7e267000 Deferred        libxi.so.6
ELF 7e267000-7e26c000 Deferred        libxcomposite.so.1
ELF 7e26c000-7e27b000 Deferred        libxrandr.so.2
ELF 7e27b000-7e289000 Deferred        libxrender.so.1
ELF 7e289000-7e291000 Deferred        libxxf86vm.so.1
ELF 7e291000-7e296000 Deferred        libxinerama.so.1
ELF 7e296000-7e2a4000 Deferred        libmd.so.0
ELF 7e2a4000-7e2bc000 Deferred        libbsd.so.0
ELF 7e2bc000-7e2c4000 Deferred        libxdmcp.so.6
ELF 7e2c4000-7e2ca000 Deferred        libxau.so.6
ELF 7e2ca000-7e2f8000 Deferred        libxcb.so.1
ELF 7e2f8000-7e44a000 Deferred        libx11.so.6
ELF 7e44a000-7e461000 Deferred        libxext.so.6
ELF 7e462000-7e467000 Deferred        libxshmfence.so.1
ELF 7e467000-7e46c000 Deferred        libxcb-shm.so.0
ELF 7e46c000-7e473000 Deferred        libxcb-dri2.so.0
ELF 7e473000-7e478000 Deferred        libx11-xcb.so.1
ELF 7e47a000-7e506000 Deferred        winex11.so
ELF 7e583000-7e58d000 Deferred        libuuid.so.1
ELF 7e58d000-7e5bd000 Deferred        libexpat.so.1
ELF 7e5bd000-7e60d000 Deferred        libfontconfig.so.1
ELF 7e60d000-7e630000 Deferred        libbrotlicommon.so.1
ELF 7e630000-7e63e000 Deferred        libbrotlidec.so.1
ELF 7e63e000-7e65c000 Deferred        libz.so.1
ELF 7e65c000-7e69c000 Deferred        libpng16.so.16
ELF 7e69c000-7e769000 Deferred        libfreetype.so.6
ELF 7e769000-7e871000 Deferred        libm.so.6
ELF 7e88a000-7e9fd000 Deferred        win32u.so
ELF 7e9fd000-7eb86000 Dwarf           libwine.so.1
PE 7fd40000-7fdd4000 Deferred        mmdevapi
ELF f7cb9000-f7d69000 Deferred        ntdll.so
ELF f7d69000-f7f9e000 Deferred        libc.so.6
ELF f7fb1000-f7fb7000 Deferred        ws2_32.so
ELF f7fb9000-f7ff1000 Deferred        ld-linux.so.2
Threads:
process  tid      prio    name (all IDs are in hex)
00000020 (D) Z:\home\leo\Tools\mmbasic\MMBasic_input.exe
00000024    0    
00000128    0    
0000012c    0    
00000138    0    
0000013c    0     wine_mmdevapi_notification
00000140   15     winepulse_mainloop
00000148    0 <==
0000014c    0     wine_xinput_hid_update
00000150   15     winepulse_timer_loop
00000154    0     wine_sechost_device_notify
00000160    0    
00000164    0    
00000168    0    
0000016c    0    
00000170   15     winepulse_timer_loop
00000174    0    
00000180    0    
00000038 services.exe
0000003c    0    
00000040    0     wine_rpcrt4_server
0000004c    0     wine_rpcrt4_io
00000078    0     wine_rpcrt4_io
00000098    0     wine_rpcrt4_io
000000ac    0     wine_rpcrt4_io
000000c4    0     wine_rpcrt4_io
000000fc    0     wine_rpcrt4_io
00000044 winedevice.exe
00000048    0    
00000054    0    
00000058    0     wine_sechost_service
0000005c    0    
00000060    0    
00000064    0    
000000d0    0    
00000068 explorer.exe
0000006c    0    
000000e4    0    
000000f8    0     wine_rpcrt4_server
00000070 winedevice.exe
00000074    0    
0000007c    0    
00000080    0     wine_sechost_service
00000084    0    
00000088    0    
0000008c    0    
00000090    0    
00000094    0    
000000a4    0    
000000a8    0    
0000009c plugplay.exe
000000a0    0    
000000b0    0    
000000b4    0     wine_sechost_service
000000b8    0     wine_rpcrt4_server
00000158    0     wine_rpcrt4_io
0000015c    0     wine_threadpool_worker
000000bc svchost.exe
000000c0    0    
000000c8    0    
000000cc    0     wine_sechost_service
000000d4 conhost.exe
000000d8    0    
000000f0 rpcss.exe
000000f4    0    
00000108    0    
00000110    0     wine_sechost_service
00000114    0     wine_rpcrt4_server
00000118    0     wine_rpcrt4_server
00000124    0     wine_rpcrt4_io
System information:
   Wine build: wine-8.0.2
   Platform: i386 (WOW64)
   Version: Windows 7
   Host system: Linux
   Host version: 5.15.0-91-generic
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 08:40am 24 Dec 2023
Copy link to clipboard 
Print this post

Please post or point me to the code for the game and I'll try it native on windows to confirm if it is a wine issue
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 03:11pm 24 Dec 2023
Copy link to clipboard 
Print this post

The source code is available on my GitHub

https://github.com/leonicolas/knightmare-cmm2
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 03:27pm 24 Dec 2023
Copy link to clipboard 
Print this post

Doesn't respond to the gamepad - what do I need to change?
 
LeoNicolas

Guru

Joined: 07/10/2020
Location: Canada
Posts: 479
Posted: 04:37pm 24 Dec 2023
Copy link to clipboard 
Print this post

The code doesn't support the gamepad yet. It is crashing even I'm no using the new commads

The code you shared to test the gamepad works fine, but the game code, that is not modified for supporting the gamepad, and that is working fine in the previous MMB4W version crashes after a couple of seconds of running
Edited 2023-12-25 02:41 by LeoNicolas
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 09:56pm 26 Dec 2023
Copy link to clipboard 
Print this post

I borrowed an Xbox controller and tried Peter's demo code above and it worked just as it says on the box. Thanks Peter, that's just what we need if people are going to develop and play games on MM4W.

I have bought a controller now, it's on it's way.

Bill
Keep safe. Live long and prosper.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 03:13am 24 Feb 2024
Copy link to clipboard 
Print this post

Hi Peter, the Xbox controller works well in Leo's knightmare game but when it announces that the controller is connected the game has already started and it overwrites the game's screen and doesn't go away. So the game must be restarted.



I guess there are work arounds but maybe if it didn't print the message and set an MM.INFO flag so that the programmer could check that and take the appropriate action that might make life easier.

Bill
Keep safe. Live long and prosper.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 09:57pm 04 Aug 2024
Copy link to clipboard 
Print this post

Hi Peter,

I don't think you ever pushed this update to the MMB4W GitHub repository. Would it need possible for you to do so?

Thanks in advance,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 06:42am 06 Aug 2024
Copy link to clipboard 
Print this post

  matherp said  V5.07.03b24


Often while I use INC i also automaticaly want to use DEC instead  INC var,-1. It`s z80 asm nostalgy and nothing else. It might be some reasons to avoid it, but would`nt it be nice to have also DEC in pair with INC?
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6781
Posted: 07:48am 06 Aug 2024
Copy link to clipboard 
Print this post

It would only be pretty. The problem is that all the keyword space in MMBasic is used (some of it, like INC, multiple times). There isn't anywhere left to put DEC.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:16am 06 Aug 2024
Copy link to clipboard 
Print this post

> LIST
Sub DEC var
 Inc Var, -1
End Sub

End
>
> g=8
> dec g
> ? g
7
>
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4036
Posted: 08:32am 06 Aug 2024
Copy link to clipboard 
Print this post

Hi folks,

@electricat, historically MMBasic was limited to ~128 commands and ~128 functions due to how it tokenises hence we have INC but not DEC.

The latest PicoMite betas no longer have this limitation for commands, though it is still present for functions, so in theory Peter could add DEC, though I personally wouldn't use it unless backported to the CMM2 + MMB4W

The SUB solution is very inefficient, as I'm sure @phil99 knows, but I will admit it looks prettier.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 08:42am 06 Aug 2024
Copy link to clipboard 
Print this post

Yes, INC on its own is very fast

INC n, n is faster than either n * 2 or n << 1

and getting to and from a Sub takes time, but for some style trumps performance.

Edit - even slower!
Sub DEC var, n%
 If n% = 0 Then n% = 1
 Inc Var, -n%
End Sub

> q=1000 : dec q : ? q
999
> q=1000 : dec q, 9 : ? q
991
>

Edited 2024-08-06 18:49 by phil99
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 02:46pm 06 Aug 2024
Copy link to clipboard 
Print this post

  Mixtel90 said  It would only be pretty. The problem is that all the keyword space in MMBasic is used (some of it, like INC, multiple times). There isn't anywhere left to put DEC.


Got it!
I will be happy with INC some_var,-x  then :)
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6781
Posted: 02:57pm 06 Aug 2024
Copy link to clipboard 
Print this post

If Peter has solved the problem, as Tom says, it might happen yet. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
electricat

Senior Member

Joined: 30/11/2020
Location: Lithuania
Posts: 161
Posted: 03:05pm 06 Aug 2024
Copy link to clipboard 
Print this post

  thwill said  
The SUB solution is very inefficient, as I'm sure @phil99 knows, but I will admit it looks prettier.


I know too SUB`s must  inefficient, and that DEC idea was only to make it pretty, yes.
I wrote once some bit manipulation functions bit.set, bit.res, bit.test only becouse it was fun and nostalgic but not the most efficient way  

So yes, there are many ways to solve same task .. CSUB`s etc.. :)  

Wrote them while writing z80 disasm :D  

function bit_res.0 (bt)
bit_res.0=bt and 254
end function

function bit_res.1 (bt)

bit_res.1=bt and 253
end function

function bit_res.2 (bt)
bit_res.2=bt and 251
end function

function bit_res.3 (bt)
bit_res.3=bt and 247
end function

function bit_res.4 (bt)
bit_res.4=bt and 239
end function

function bit_res.5 (bt)
bit_res.5=bt and 223
end function

function bit_res.6 (bt)
bit_res.6=bt and 191
end function

function bit_res.7 (bt)
bit_res.7=bt and  127
end function




function bit_set.0 (bt)
bit_set.0=bt or 1
end function

function bit_set.1 (bt)
bit_set.1=bt or 2
end function

function bit_set.2 (bt)
bit_set.2=bt or 4
end function

function bit_set.3 (bt)
bit_set.3=bt or 8
end function

function bit_set.4 (bt)
bit_set.4=bt or 16
end function

function bit_set.5 (bt)
bit_set.5=bt or 32
end function

function bit_set.6 (bt)
bit_set.6=bt or 64
end function

function bit_set.7 (bt)
bit_set.7=bt or 128
end function




' test bit. If bit set, returns 1 if offset returns 0

function bit.0 (test_byte) as integer
bit.0=(test_byte and 1)
end function

function bit.1 (test_byte) as integer
bit.1=(test_byte and 2) >> 1
end function

function bit.2 (test_byte) as integer
bit.2=(test_byte and 4) >> 2
end function

function bit.3 (test_byte) as integer
bit.3=(test_byte and 8) >> 3
end function

function bit.4 (test_byte) as integer
bit.4=(test_byte and 16) >> 4
end function

function bit.5 (test_byte) as integer
bit.5=(test_byte and 32) >> 5
end function

function bit.6 (test_byte) as integer
bit.6=(test_byte and 64) >> 6
end function

function bit.7 (test_byte) as integer
bit.7=(test_byte and 128) >> 7
end function
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024